Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -274,19 +274,22 @@
},
{
"name": "godbolt-minimal",
"displayName": "Godbolt / Sandboxed Environment",
"description": "Minimal single-node static build optimized for browser-based compilers (Compiler Explorer / Godbolt). Uses system malloc, disables networking, tests, examples, and documentation to minimize binary size and build time.",
"displayName": "Compiler Explorer / Godbolt (Minimal)",
"description": "Minimal single-node static build for Compiler Explorer (godbolt.org) and similar sandboxed environments. Statically links all HPX libraries, disables the distributed runtime and networking, fetches Asio via FetchContent, and uses the system allocator. Skips tests, examples, documentation, and tools to minimize build time. Produces libhpx_wrap.a, libhpx_init.a, libhpx.a, and libhpx_core.a suitable for use with -Wl,-wrap=main on Linux.",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build/godbolt-minimal",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
"HPX_WITH_MALLOC": "system",
"HPX_WITH_CXX_STANDARD": "20",
"HPX_WITH_STATIC_LINKING": "ON",
"HPX_WITH_DISTRIBUTED_RUNTIME": "OFF",
"HPX_WITH_NETWORKING": "OFF",
"HPX_WITH_FETCH_ASIO": "ON",
"HPX_WITH_MALLOC": "system",
"HPX_WITH_TESTS": "OFF",
"HPX_WITH_EXAMPLES": "OFF",
"HPX_WITH_DOCUMENTATION": "OFF",
"HPX_WITH_STATIC_LINKING": "ON",
"HPX_WITH_FETCH_ASIO": "ON"
"HPX_WITH_TOOLS": "OFF"
}
}
],
Expand Down
6 changes: 3 additions & 3 deletions libs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -433,10 +433,10 @@ foreach(lib ${HPX_LIBS})
)

# Clang emits DWARF-5 records while compiling the TracyClient library
if(HPX_TRACY_WITH_TRACY
if(HPX_WITH_TRACY
AND (NOT MSVC)
AND (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID
MATCHES "AppleClang")
AND (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
AND (NOT (CMAKE_CXX_COMPILER_ID MATCHES "AppleClang"))
)
target_link_options(hpx_${lib} PRIVATE "-fuse-ld=lld")
endif()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ namespace hpx {
hpx::traits::is_iterator_v<OutIter> &&
hpx::is_invocable_v<Pred,
hpx::traits::iter_value_t<InIter>,
hpx::traits::iter_value_t<OutIter>
hpx::traits::iter_value_t<InIter>
>
)
// clang-format on
Expand All @@ -775,7 +775,7 @@ namespace hpx {
hpx::traits::is_iterator_v<FwdIter2> &&
hpx::is_invocable_v<Pred,
hpx::traits::iter_value_t<FwdIter1>,
hpx::traits::iter_value_t<FwdIter2>
hpx::traits::iter_value_t<FwdIter1>
>
)
// clang-format on
Expand Down
12 changes: 12 additions & 0 deletions libs/core/algorithms/tests/unit/algorithms/unique_copy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ void unique_copy_bad_alloc_test()
test_unique_copy_bad_alloc<std::forward_iterator_tag>();
}

void unique_copy_constraint_test()
{
std::cout << "--- unique_copy_constraint_test ---" << std::endl;
// Exercises the corrected predicate constraint in hpx::unique_copy:
// the requires clause must check iter_value_t<InIter> for both arguments,
// not iter_value_t<OutIter> for the second argument.
test_unique_copy_constraint<std::random_access_iterator_tag>();
test_unique_copy_constraint<std::bidirectional_iterator_tag>();
test_unique_copy_constraint<std::forward_iterator_tag>();
}

///////////////////////////////////////////////////////////////////////////////
int hpx_main(hpx::program_options::variables_map& vm)
{
Expand All @@ -53,6 +64,7 @@ int hpx_main(hpx::program_options::variables_map& vm)
unique_copy_test();
unique_copy_exception_test();
unique_copy_bad_alloc_test();
unique_copy_constraint_test();

std::cout << "Test Finish!" << std::endl;

Expand Down
169 changes: 169 additions & 0 deletions libs/core/algorithms/tests/unit/algorithms/unique_copy_tests.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,3 +518,172 @@ void test_unique_copy_bad_alloc()
test_unique_copy_bad_alloc_async(seq(task), IteratorTag());
test_unique_copy_bad_alloc_async(par(task), IteratorTag());
}

///////////////////////////////////////////////////////////////////////////////
// Verify that the predicate constraint in hpx::unique_copy is checked against
// the INPUT iterator's value type (iter_value_t<InIter>), not the output
// iterator's value type. This directly exercises the corrected requires clause.
//
// All calls use a predicate typed explicitly on int (the input element type),
// confirming the CPO correctly dispatches with a strongly-typed binary predicate
// across all execution policies.
template <typename IteratorTag>
void test_unique_copy_constraint()
{
using namespace hpx::execution;
using base_iterator = std::vector<int>::iterator;
using iterator = test::test_iterator<base_iterator, IteratorTag>;

// Strongly-typed binary predicate on the input element type (int).
// Before the fix, the parallel overload's requires clause checked
// is_invocable_v<Pred, iter_value_t<FwdIter1>, iter_value_t<FwdIter2>>,
// which could silently mis-constrain when InIter and OutIter differ.
auto typed_pred = [](int const a, int const b) -> bool { return a == b; };

std::size_t const size = 10007;
std::vector<int> c(size), dest_res(size), dest_sol(size);
std::generate(std::begin(c), std::end(c), random_fill(0, 6));

// --- seq policy ---
{
auto result = hpx::unique_copy(seq, iterator(std::begin(c)),
iterator(std::end(c)), iterator(std::begin(dest_res)), typed_pred);
auto solution = std::unique_copy(std::begin(c), std::end(c),
std::begin(dest_sol), [](int a, int b) { return a == b; });
HPX_TEST(test::equal(std::begin(dest_res), result.base(),
std::begin(dest_sol), solution));
}

// --- par policy ---
{
auto result = hpx::unique_copy(par, iterator(std::begin(c)),
iterator(std::end(c)), iterator(std::begin(dest_res)), typed_pred);
auto solution = std::unique_copy(std::begin(c), std::end(c),
std::begin(dest_sol), [](int a, int b) { return a == b; });
HPX_TEST(test::equal(std::begin(dest_res), result.base(),
std::begin(dest_sol), solution));
}

// --- par_unseq policy ---
{
auto result = hpx::unique_copy(par_unseq, iterator(std::begin(c)),
iterator(std::end(c)), iterator(std::begin(dest_res)), typed_pred);
auto solution = std::unique_copy(std::begin(c), std::end(c),
std::begin(dest_sol), [](int a, int b) { return a == b; });
HPX_TEST(test::equal(std::begin(dest_res), result.base(),
std::begin(dest_sol), solution));
}

// --- seq(task) async ---
{
auto f = hpx::unique_copy(seq(task), iterator(std::begin(c)),
iterator(std::end(c)), iterator(std::begin(dest_res)), typed_pred);
auto result = f.get();
auto solution = std::unique_copy(std::begin(c), std::end(c),
std::begin(dest_sol), [](int a, int b) { return a == b; });
HPX_TEST(test::equal(std::begin(dest_res), result.base(),
std::begin(dest_sol), solution));
}

// --- par(task) async ---
{
auto f = hpx::unique_copy(par(task), iterator(std::begin(c)),
iterator(std::end(c)), iterator(std::begin(dest_res)), typed_pred);
auto result = f.get();
auto solution = std::unique_copy(std::begin(c), std::end(c),
std::begin(dest_sol), [](int a, int b) { return a == b; });
HPX_TEST(test::equal(std::begin(dest_res), result.base(),
std::begin(dest_sol), solution));
}

// --- Edge case: empty range ---
// Ensures the constraint does not misfire on zero-length inputs.
{
std::vector<int> empty_src;
std::vector<int> empty_dst;
auto result = hpx::unique_copy(par, empty_src.begin(), empty_src.end(),
empty_dst.begin(), typed_pred);
HPX_TEST(result == empty_dst.begin());

result = hpx::unique_copy(seq, empty_src.begin(), empty_src.end(),
empty_dst.begin(), typed_pred);
HPX_TEST(result == empty_dst.begin());
}

// --- Edge case: single element ---
// Must copy the one element verbatim; no predicate calls occur.
{
std::vector<int> single_src = {42};
std::vector<int> single_dst(1, 0);

auto result = hpx::unique_copy(seq, single_src.begin(),
single_src.end(), single_dst.begin(), typed_pred);
HPX_TEST(result == single_dst.begin() + 1);
HPX_TEST(single_dst[0] == 42);

result = hpx::unique_copy(par, single_src.begin(), single_src.end(),
single_dst.begin(), typed_pred);
HPX_TEST(result == single_dst.begin() + 1);
HPX_TEST(single_dst[0] == 42);
}

// --- Edge case: all elements identical -> only one element in output ---
{
std::vector<int> all_same(100, 7);
std::vector<int> dst_res(100, 0), dst_sol(100, 0);

auto result = hpx::unique_copy(
par, all_same.begin(), all_same.end(), dst_res.begin(), typed_pred);
auto solution = std::unique_copy(all_same.begin(), all_same.end(),
dst_sol.begin(), [](int a, int b) { return a == b; });

HPX_TEST(result == dst_res.begin() + 1);
HPX_TEST(
test::equal(dst_res.begin(), result, dst_sol.begin(), solution));
}

// --- Edge case: no consecutive duplicates -> full copy ---
{
std::vector<int> no_dup = {1, 2, 3, 4, 5};
std::vector<int> dst_res(5, 0), dst_sol(5, 0);

auto result = hpx::unique_copy(
par, no_dup.begin(), no_dup.end(), dst_res.begin(), typed_pred);
auto solution = std::unique_copy(no_dup.begin(), no_dup.end(),
dst_sol.begin(), [](int a, int b) { return a == b; });

HPX_TEST(result == dst_res.begin() + 5);
HPX_TEST(
test::equal(dst_res.begin(), result, dst_sol.begin(), solution));
}

// --- Edge case: two elements, identical ---
{
std::vector<int> two_same = {9, 9};
std::vector<int> dst_res(2, 0), dst_sol(2, 0);

auto result = hpx::unique_copy(
par, two_same.begin(), two_same.end(), dst_res.begin(), typed_pred);
auto solution = std::unique_copy(two_same.begin(), two_same.end(),
dst_sol.begin(), [](int a, int b) { return a == b; });

HPX_TEST(result == dst_res.begin() + 1);
HPX_TEST(
test::equal(dst_res.begin(), result, dst_sol.begin(), solution));
}

// --- Edge case: two elements, distinct ---
{
std::vector<int> two_diff = {3, 5};
std::vector<int> dst_res(2, 0), dst_sol(2, 0);

auto result = hpx::unique_copy(
par, two_diff.begin(), two_diff.end(), dst_res.begin(), typed_pred);
auto solution = std::unique_copy(two_diff.begin(), two_diff.end(),
dst_sol.begin(), [](int a, int b) { return a == b; });

HPX_TEST(result == dst_res.begin() + 2);
HPX_TEST(
test::equal(dst_res.begin(), result, dst_sol.begin(), solution));
}
}
3 changes: 3 additions & 0 deletions libs/core/executors/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ set(executors_headers
hpx/executors/execution_policy_parameters.hpp
hpx/executors/execution_policy_scheduling_property.hpp
hpx/executors/execution_policy.hpp
hpx/executors/executor_scheduler.hpp
hpx/executors/executor_scheduler_bulk.hpp
hpx/executors/executor_scheduler_fwd.hpp
hpx/executors/explicit_scheduler_executor.hpp
hpx/executors/fork_join_executor.hpp
hpx/executors/limiting_executor.hpp
Expand Down
Loading
Loading