Skip to content

Commit 04b4545

Browse files
authored
[libc++] Explicitly pass execution policies to _LIBCPP_PSTL_CUSTOMIZATION_POINT (#68238)
The _LIBCPP_PSTL_CUSTOMIZATION_POINT macro was assuming that the policy was called _RawPolicy and referencing it by name. It happened to always work but this was definitely accidental and an oversight in the original implementation. This patch fixes that by passing the policy to the macro explicitly. Noticed while reviewing #66968.
1 parent e599422 commit 04b4545

12 files changed

+26
-27
lines changed

libcxx/include/__algorithm/pstl_any_all_none_of.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI bool
3939
any_of(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) {
4040
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator);
4141
return std::__pstl_frontend_dispatch(
42-
_LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_any_of),
42+
_LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_any_of, _RawPolicy),
4343
[&](_ForwardIterator __g_first, _ForwardIterator __g_last, _Predicate __g_pred) {
4444
return std::find_if(__policy, __g_first, __g_last, __g_pred) != __g_last;
4545
},
@@ -60,7 +60,7 @@ _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI bool
6060
all_of(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Pred __pred) {
6161
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator);
6262
return std::__pstl_frontend_dispatch(
63-
_LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_all_of),
63+
_LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_all_of, _RawPolicy),
6464
[&](_ForwardIterator __g_first, _ForwardIterator __g_last, _Pred __g_pred) {
6565
return !std::any_of(__policy, __g_first, __g_last, [&](__iter_reference<_ForwardIterator> __value) {
6666
return !__g_pred(__value);
@@ -83,7 +83,7 @@ _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI bool
8383
none_of(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Pred __pred) {
8484
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator);
8585
return std::__pstl_frontend_dispatch(
86-
_LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_none_of),
86+
_LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_none_of, _RawPolicy),
8787
[&](_ForwardIterator __g_first, _ForwardIterator __g_last, _Pred __g_pred) {
8888
return !std::any_of(__policy, __g_first, __g_last, __g_pred);
8989
},

libcxx/include/__algorithm/pstl_copy.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ template <class _ExecutionPolicy,
4444
_LIBCPP_HIDE_FROM_ABI _ForwardOutIterator
4545
copy(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _ForwardOutIterator __result) {
4646
return std::__pstl_frontend_dispatch(
47-
_LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_copy),
47+
_LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_copy, _RawPolicy),
4848
[&__policy](_ForwardIterator __g_first, _ForwardIterator __g_last, _ForwardOutIterator __g_result) {
4949
return std::transform(__policy, __g_first, __g_last, __g_result, __identity());
5050
},
@@ -65,7 +65,7 @@ template <class _ExecutionPolicy,
6565
_LIBCPP_HIDE_FROM_ABI _ForwardOutIterator
6666
copy_n(_ExecutionPolicy&& __policy, _ForwardIterator __first, _Size __n, _ForwardOutIterator __result) {
6767
return std::__pstl_frontend_dispatch(
68-
_LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_copy_n),
68+
_LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_copy_n, _RawPolicy),
6969
[&__policy](_ForwardIterator __g_first, _Size __g_n, _ForwardOutIterator __g_result) {
7070
if constexpr (__has_random_access_iterator_category_or_concept<_ForwardIterator>::value)
7171
return std::copy(__policy, __g_first, __g_first + __g_n, __g_result);

libcxx/include/__algorithm/pstl_count.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ _LIBCPP_HIDE_FROM_ABI __iter_diff_t<_ForwardIterator>
4545
count_if(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) {
4646
using __diff_t = __iter_diff_t<_ForwardIterator>;
4747
return std::__pstl_frontend_dispatch(
48-
_LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_count_if),
48+
_LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_count_if, _RawPolicy),
4949
[&](_ForwardIterator __g_first, _ForwardIterator __g_last, _Predicate __g_pred) {
5050
return std::transform_reduce(
5151
__policy,
@@ -71,7 +71,7 @@ template <class _ExecutionPolicy,
7171
_LIBCPP_HIDE_FROM_ABI __iter_diff_t<_ForwardIterator>
7272
count(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) {
7373
return std::__pstl_frontend_dispatch(
74-
_LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_count),
74+
_LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_count, _RawPolicy),
7575
[&](_ForwardIterator __g_first, _ForwardIterator __g_last, const _Tp& __g_value) {
7676
return std::count_if(__policy, __g_first, __g_last, [&](__iter_reference<_ForwardIterator> __v) {
7777
return __v == __g_value;

libcxx/include/__algorithm/pstl_fill.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ _LIBCPP_HIDE_FROM_ABI void
4242
fill(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) {
4343
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator);
4444
std::__pstl_frontend_dispatch(
45-
_LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_fill),
45+
_LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_fill, _RawPolicy),
4646
[&](_ForwardIterator __g_first, _ForwardIterator __g_last, const _Tp& __g_value) {
4747
std::for_each(__policy, __g_first, __g_last, [&](__iter_reference<_ForwardIterator> __element) {
4848
__element = __g_value;
@@ -66,7 +66,7 @@ _LIBCPP_HIDE_FROM_ABI void
6666
fill_n(_ExecutionPolicy&& __policy, _ForwardIterator __first, _SizeT __n, const _Tp& __value) {
6767
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator);
6868
std::__pstl_frontend_dispatch(
69-
_LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_fill_n),
69+
_LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_fill_n, _RawPolicy),
7070
[&](_ForwardIterator __g_first, _SizeT __g_n, const _Tp& __g_value) {
7171
if constexpr (__has_random_access_iterator_category_or_concept<_ForwardIterator>::value)
7272
std::fill(__policy, __g_first, __g_first + __g_n, __g_value);

libcxx/include/__algorithm/pstl_find.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ _LIBCPP_HIDE_FROM_ABI _ForwardIterator
5353
find_if_not(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) {
5454
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator);
5555
return std::__pstl_frontend_dispatch(
56-
_LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_find_if_not),
56+
_LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_find_if_not, _RawPolicy),
5757
[&](_ForwardIterator __g_first, _ForwardIterator __g_last, _Predicate __g_pred) {
5858
return std::find_if(__policy, __g_first, __g_last, [&](__iter_reference<_ForwardIterator> __value) {
5959
return !__g_pred(__value);
@@ -76,7 +76,7 @@ _LIBCPP_HIDE_FROM_ABI _ForwardIterator
7676
find(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) {
7777
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator);
7878
return std::__pstl_frontend_dispatch(
79-
_LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_find),
79+
_LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_find, _RawPolicy),
8080
[&](_ForwardIterator __g_first, _ForwardIterator __g_last, const _Tp& __g_value) {
8181
return std::find_if(__policy, __g_first, __g_last, [&](__iter_reference<_ForwardIterator> __element) {
8282
return __element == __g_value;

libcxx/include/__algorithm/pstl_for_each.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ _LIBCPP_HIDE_FROM_ABI void
5656
for_each_n(_ExecutionPolicy&& __policy, _ForwardIterator __first, _Size __size, _Function __func) {
5757
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator);
5858
return std::__pstl_frontend_dispatch(
59-
_LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_for_each_n),
59+
_LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_for_each_n, _RawPolicy),
6060
[&](_ForwardIterator __g_first, _Size __g_size, _Function __g_func) {
6161
if constexpr (__has_random_access_iterator_category_or_concept<_ForwardIterator>::value) {
6262
std::for_each(__policy, std::move(__g_first), __g_first + __g_size, std::move(__g_func));

libcxx/include/__algorithm/pstl_frontend_dispatch.h

+4-5
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@
2121

2222
_LIBCPP_BEGIN_NAMESPACE_STD
2323

24-
# define _LIBCPP_PSTL_CUSTOMIZATION_POINT(name) \
25-
[](auto&&... __args) -> decltype(std::name<_RawPolicy>(typename __select_backend<_RawPolicy>::type{}, \
26-
std::forward<decltype(__args)>(__args)...)) { \
27-
return std::name<_RawPolicy>( \
28-
typename __select_backend<_RawPolicy>::type{}, std::forward<decltype(__args)>(__args)...); \
24+
# define _LIBCPP_PSTL_CUSTOMIZATION_POINT(name, policy) \
25+
[](auto&&... __args) -> decltype(std::name<policy>( \
26+
typename __select_backend<policy>::type{}, std::forward<decltype(__args)>(__args)...)) { \
27+
return std::name<policy>(typename __select_backend<policy>::type{}, std::forward<decltype(__args)>(__args)...); \
2928
}
3029

3130
template <class _SpecializedImpl, class _GenericImpl, class... _Args>

libcxx/include/__algorithm/pstl_generate.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ _LIBCPP_HIDE_FROM_ABI void
4040
generate(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Generator __gen) {
4141
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator);
4242
std::__pstl_frontend_dispatch(
43-
_LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_generate),
43+
_LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_generate, _RawPolicy),
4444
[&__policy](_ForwardIterator __g_first, _ForwardIterator __g_last, _Generator __g_gen) {
4545
std::for_each(
4646
__policy, std::move(__g_first), std::move(__g_last), [&](__iter_reference<_ForwardIterator> __element) {
@@ -65,7 +65,7 @@ _LIBCPP_HIDE_FROM_ABI void
6565
generate_n(_ExecutionPolicy&& __policy, _ForwardIterator __first, _Size __n, _Generator __gen) {
6666
_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator);
6767
std::__pstl_frontend_dispatch(
68-
_LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_generate_n),
68+
_LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_generate_n, _RawPolicy),
6969
[&__policy](_ForwardIterator __g_first, _Size __g_n, _Generator __g_gen) {
7070
std::for_each_n(__policy, std::move(__g_first), __g_n, [&](__iter_reference<_ForwardIterator> __element) {
7171
__element = __g_gen();

libcxx/include/__algorithm/pstl_is_partitioned.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ template <class _ExecutionPolicy,
3838
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI bool
3939
is_partitioned(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) {
4040
return std::__pstl_frontend_dispatch(
41-
_LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_is_partitioned),
41+
_LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_is_partitioned, _RawPolicy),
4242
[&__policy](_ForwardIterator __g_first, _ForwardIterator __g_last, _Predicate __g_pred) {
4343
__g_first = std::find_if_not(__policy, __g_first, __g_last, __g_pred);
4444
if (__g_first == __g_last)

libcxx/include/__algorithm/pstl_replace.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ replace_if(_ExecutionPolicy&& __policy,
4343
_Pred __pred,
4444
const _Tp& __new_value) {
4545
std::__pstl_frontend_dispatch(
46-
_LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_replace_if),
46+
_LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_replace_if, _RawPolicy),
4747
[&__policy](_ForwardIterator __g_first, _ForwardIterator __g_last, _Pred __g_pred, const _Tp& __g_new_value) {
4848
std::for_each(__policy, __g_first, __g_last, [&](__iter_reference<_ForwardIterator> __element) {
4949
if (__g_pred(__element))
@@ -71,7 +71,7 @@ replace(_ExecutionPolicy&& __policy,
7171
const _Tp& __old_value,
7272
const _Tp& __new_value) {
7373
std::__pstl_frontend_dispatch(
74-
_LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_replace),
74+
_LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_replace, _RawPolicy),
7575
[&__policy](
7676
_ForwardIterator __g_first, _ForwardIterator __g_last, const _Tp& __g_old_value, const _Tp& __g_new_value) {
7777
std::replace_if(
@@ -105,7 +105,7 @@ _LIBCPP_HIDE_FROM_ABI void replace_copy_if(
105105
_Pred __pred,
106106
const _Tp& __new_value) {
107107
std::__pstl_frontend_dispatch(
108-
_LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_replace_copy_if),
108+
_LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_replace_copy_if, _RawPolicy),
109109
[&__policy](_ForwardIterator __g_first,
110110
_ForwardIterator __g_last,
111111
_ForwardOutIterator __g_result,
@@ -139,7 +139,7 @@ _LIBCPP_HIDE_FROM_ABI void replace_copy(
139139
const _Tp& __old_value,
140140
const _Tp& __new_value) {
141141
std::__pstl_frontend_dispatch(
142-
_LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_replace_copy),
142+
_LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_replace_copy, _RawPolicy),
143143
[&__policy](_ForwardIterator __g_first,
144144
_ForwardIterator __g_last,
145145
_ForwardOutIterator __g_result,

libcxx/include/__algorithm/pstl_sort.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ template <class _ExecutionPolicy,
3838
_LIBCPP_HIDE_FROM_ABI void
3939
sort(_ExecutionPolicy&& __policy, _RandomAccessIterator __first, _RandomAccessIterator __last, _Comp __comp) {
4040
std::__pstl_frontend_dispatch(
41-
_LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_sort),
41+
_LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_sort, _RawPolicy),
4242
[&__policy](_RandomAccessIterator __g_first, _RandomAccessIterator __g_last, _Comp __g_comp) {
4343
std::stable_sort(__policy, std::move(__g_first), std::move(__g_last), std::move(__g_comp));
4444
},

libcxx/include/__numeric/pstl_reduce.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ reduce(_ExecutionPolicy&& __policy,
4040
_Tp __init,
4141
_BinaryOperation __op = {}) {
4242
return std::__pstl_frontend_dispatch(
43-
_LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_reduce),
43+
_LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_reduce, _RawPolicy),
4444
[&__policy](_ForwardIterator __g_first, _ForwardIterator __g_last, _Tp __g_init, _BinaryOperation __g_op) {
4545
return std::transform_reduce(
4646
__policy, std::move(__g_first), std::move(__g_last), std::move(__g_init), std::move(__g_op), __identity{});
@@ -58,7 +58,7 @@ template <class _ExecutionPolicy,
5858
_LIBCPP_HIDE_FROM_ABI __iter_value_type<_ForwardIterator>
5959
reduce(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last) {
6060
return std::__pstl_frontend_dispatch(
61-
_LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_reduce),
61+
_LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_reduce, _RawPolicy),
6262
[&__policy](_ForwardIterator __g_first, _ForwardIterator __g_last) {
6363
return std::reduce(__policy, __g_first, __g_last, __iter_value_type<_ForwardIterator>());
6464
},

0 commit comments

Comments
 (0)