Skip to content

update relocation definitions to track p2786r13 standard#6869

Open
guptapratykshh wants to merge 5 commits intoTheHPXProject:masterfrom
guptapratykshh:fix/issue-6625-update-relocation
Open

update relocation definitions to track p2786r13 standard#6869
guptapratykshh wants to merge 5 commits intoTheHPXProject:masterfrom
guptapratykshh:fix/issue-6625-update-relocation

Conversation

@guptapratykshh
Copy link
Copy Markdown
Contributor

Fixes #6625

Proposed Changes

  • added is_replaceable trait to align with p2786r13
  • updated is_trivially_relocatable to use the standard version if the c++26 feature macro is present
  • wired up relocate_at to call std::relocate_at when available

Any background context you want to provide?

Checklist

Not all points below apply to all pull requests.

  • I have added a new feature and have added tests to go along with it.
  • I have fixed a bug and have added a regression test.
  • I have added a test using random numbers; I have made sure it uses a seed, and that random numbers generated are valid inputs for the tests.

@StellarBot
Copy link
Copy Markdown

Can one of the admins verify this patch?

@hkaiser
Copy link
Copy Markdown
Contributor

hkaiser commented Feb 2, 2026

@isidorostsa Would you please have a look?

Copy link
Copy Markdown
Contributor

@isidorostsa isidorostsa left a comment

Choose a reason for hiding this comment

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

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>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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);        // 2

You 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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Are array types not replaceable?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Comment thread libs/core/type_support/tests/unit/is_replaceable.cpp Outdated
#include <mutex>
#include <type_traits>

using hpx::experimental::is_replaceable_v;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Those tests should be updated in accordance with the changes in the implementation of the replacabillity trait.

Copy link
Copy Markdown
Contributor

@isidorostsa isidorostsa left a comment

Choose a reason for hiding this comment

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

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!

@guptapratykshh
Copy link
Copy Markdown
Contributor Author

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.

@isidorostsa
Copy link
Copy Markdown
Contributor

Good work, the trait is mostly correct, now you should add the opt in mechanism and the tests to check for that :)

@guptapratykshh
Copy link
Copy Markdown
Contributor Author

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

@hkaiser
Copy link
Copy Markdown
Contributor

hkaiser commented Feb 8, 2026

@guptapratykshh Could you please rebase your branch onto master (and resolve the conflicts)?

@guptapratykshh guptapratykshh force-pushed the fix/issue-6625-update-relocation branch from c119545 to 254bc27 Compare February 8, 2026 18:30
@guptapratykshh
Copy link
Copy Markdown
Contributor Author

have rebased the branch , please have a look @isidorostsa

@guptapratykshh
Copy link
Copy Markdown
Contributor Author

ping @isidorostsa @hkaiser

@guptapratykshh
Copy link
Copy Markdown
Contributor Author

@isidorostsa can you please have a look at this and review , i have addressed all changes that were there

@isidorostsa
Copy link
Copy Markdown
Contributor

@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

@guptapratykshh
Copy link
Copy Markdown
Contributor Author

hello @isidorostsa , did you have to time to check and review this

Copy link
Copy Markdown
Contributor

@isidorostsa isidorostsa left a comment

Choose a reason for hiding this comment

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

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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why is that?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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>);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is destructibility a requirement of replaceability?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes, implicit replaceability requires trivial relocatability, which requires trivial destructibility

Comment thread libs/core/type_support/include/hpx/type_support/is_replaceable.hpp
Signed-off-by: guptapratykshh <pratykshgupta9999@gmail.com>
Signed-off-by: guptapratykshh <pratykshgupta9999@gmail.com>
Signed-off-by: guptapratykshh <pratykshgupta9999@gmail.com>
@guptapratykshh guptapratykshh force-pushed the fix/issue-6625-update-relocation branch from 1f820c0 to 976a1da Compare March 3, 2026 18:28
Signed-off-by: guptapratykshh <pratykshgupta9999@gmail.com>
@guptapratykshh guptapratykshh force-pushed the fix/issue-6625-update-relocation branch from 976a1da to 37063e4 Compare March 3, 2026 19:39
@hkaiser
Copy link
Copy Markdown
Contributor

hkaiser commented Mar 9, 2026

@guptapratykshh @isidorostsa Any progress here?

@isidorostsa
Copy link
Copy Markdown
Contributor

@guptapratykshh could you please address the questions in the review? Thanks for the work!

Signed-off-by: guptapratykshh <pratykshgupta9999@gmail.com>
@guptapratykshh guptapratykshh force-pushed the fix/issue-6625-update-relocation branch from 8a482fc to 9d857b6 Compare March 16, 2026 14:04
@guptapratykshh
Copy link
Copy Markdown
Contributor Author

@isidorostsa can you please review this PR

Copy link
Copy Markdown
Contributor

@hkaiser hkaiser left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@guptapratykshh
Copy link
Copy Markdown
Contributor Author

hi @isidorostsa, i have commented on the questions that were asked in the previous comments. please have a look at that , have addresed them

@guptapratykshh
Copy link
Copy Markdown
Contributor Author

hi @isidorostsa, any updates on this PR

@codacy-production
Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

TIP This summary will be updated as you push new changes. Give us feedback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update relocation semantics to match P2786R13

4 participants