Skip to content

Commit c7c6413

Browse files
committedMar 29, 2019
[pstl] Qualify calls to internal functions
This guards against unintended ADL issues. Thanks to Thomas Rogers for the patch. Differential Revision: https://reviews.llvm.org/D60009 llvm-svn: 357306
1 parent 347a45c commit c7c6413

8 files changed

+460
-441
lines changed
 

‎pstl/include/pstl/internal/algorithm_impl.h

Lines changed: 287 additions & 279 deletions
Large diffs are not rendered by default.

‎pstl/include/pstl/internal/execution_defs.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,27 +123,27 @@ struct is_execution_policy : std::false_type
123123
};
124124

125125
template <>
126-
struct is_execution_policy<sequenced_policy> : std::true_type
126+
struct is_execution_policy<__pstl::execution::sequenced_policy> : std::true_type
127127
{
128128
};
129129
#if __PSTL_USE_PAR_POLICIES
130130
template <>
131-
struct is_execution_policy<parallel_policy> : std::true_type
131+
struct is_execution_policy<__pstl::execution::parallel_policy> : std::true_type
132132
{
133133
};
134134
template <>
135-
struct is_execution_policy<parallel_unsequenced_policy> : std::true_type
135+
struct is_execution_policy<__pstl::execution::parallel_unsequenced_policy> : std::true_type
136136
{
137137
};
138138
#endif
139139
template <>
140-
struct is_execution_policy<unsequenced_policy> : std::true_type
140+
struct is_execution_policy<__pstl::execution::unsequenced_policy> : std::true_type
141141
{
142142
};
143143

144144
#if __PSTL_CPP14_VARIABLE_TEMPLATES_PRESENT
145145
template <class T>
146-
constexpr bool is_execution_policy_v = is_execution_policy<T>::value;
146+
constexpr bool is_execution_policy_v = __pstl::execution::is_execution_policy<T>::value;
147147
#endif
148148

149149
} // namespace v1

‎pstl/include/pstl/internal/execution_impl.h

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ __lazy_or(_Tp __a, std::false_type)
5454
template <typename _IteratorType, typename... _OtherIteratorTypes>
5555
struct __is_random_access_iterator
5656
{
57-
static constexpr bool value =
58-
__is_random_access_iterator<_IteratorType>::value && __is_random_access_iterator<_OtherIteratorTypes...>::value;
57+
static constexpr bool value = __internal::__is_random_access_iterator<_IteratorType>::value &&
58+
__internal::__is_random_access_iterator<_OtherIteratorTypes...>::value;
5959
typedef std::integral_constant<bool, value> type;
6060
};
6161

@@ -106,46 +106,54 @@ struct __policy_traits<parallel_unsequenced_policy>
106106
#endif
107107

108108
template <typename _ExecutionPolicy>
109-
using __collector_t = typename __policy_traits<typename std::decay<_ExecutionPolicy>::type>::__collector_type;
109+
using __collector_t =
110+
typename __internal::__policy_traits<typename std::decay<_ExecutionPolicy>::type>::__collector_type;
110111

111112
template <typename _ExecutionPolicy>
112-
using __allow_vector = typename __policy_traits<typename std::decay<_ExecutionPolicy>::type>::__allow_vector;
113+
using __allow_vector =
114+
typename __internal::__policy_traits<typename std::decay<_ExecutionPolicy>::type>::__allow_vector;
113115

114116
template <typename _ExecutionPolicy>
115-
using __allow_unsequenced = typename __policy_traits<typename std::decay<_ExecutionPolicy>::type>::__allow_unsequenced;
117+
using __allow_unsequenced =
118+
typename __internal::__policy_traits<typename std::decay<_ExecutionPolicy>::type>::__allow_unsequenced;
116119

117120
template <typename _ExecutionPolicy>
118-
using __allow_parallel = typename __policy_traits<typename std::decay<_ExecutionPolicy>::type>::__allow_parallel;
121+
using __allow_parallel =
122+
typename __internal::__policy_traits<typename std::decay<_ExecutionPolicy>::type>::__allow_parallel;
119123

120124
template <typename _ExecutionPolicy, typename... _IteratorTypes>
121125
auto
122126
__is_vectorization_preferred(_ExecutionPolicy&& __exec)
123-
-> decltype(__lazy_and(__exec.__allow_vector(), typename __is_random_access_iterator<_IteratorTypes...>::type()))
127+
-> decltype(__internal::__lazy_and(__exec.__allow_vector(),
128+
typename __internal::__is_random_access_iterator<_IteratorTypes...>::type()))
124129
{
125-
return __lazy_and(__exec.__allow_vector(), typename __is_random_access_iterator<_IteratorTypes...>::type());
130+
return __internal::__lazy_and(__exec.__allow_vector(),
131+
typename __internal::__is_random_access_iterator<_IteratorTypes...>::type());
126132
}
127133

128134
template <typename _ExecutionPolicy, typename... _IteratorTypes>
129135
auto
130136
__is_parallelization_preferred(_ExecutionPolicy&& __exec)
131-
-> decltype(__lazy_and(__exec.__allow_parallel(), typename __is_random_access_iterator<_IteratorTypes...>::type()))
137+
-> decltype(__internal::__lazy_and(__exec.__allow_parallel(),
138+
typename __internal::__is_random_access_iterator<_IteratorTypes...>::type()))
132139
{
133-
return __lazy_and(__exec.__allow_parallel(), typename __is_random_access_iterator<_IteratorTypes...>::type());
140+
return __internal::__lazy_and(__exec.__allow_parallel(),
141+
typename __internal::__is_random_access_iterator<_IteratorTypes...>::type());
134142
}
135143

136144
template <typename policy, typename... _IteratorTypes>
137145
struct __prefer_unsequenced_tag
138146
{
139-
static constexpr bool value =
140-
__allow_unsequenced<policy>::value && __is_random_access_iterator<_IteratorTypes...>::value;
147+
static constexpr bool value = __internal::__allow_unsequenced<policy>::value &&
148+
__internal::__is_random_access_iterator<_IteratorTypes...>::value;
141149
typedef std::integral_constant<bool, value> type;
142150
};
143151

144152
template <typename policy, typename... _IteratorTypes>
145153
struct __prefer_parallel_tag
146154
{
147-
static constexpr bool value =
148-
__allow_parallel<policy>::value && __is_random_access_iterator<_IteratorTypes...>::value;
155+
static constexpr bool value = __internal::__allow_parallel<policy>::value &&
156+
__internal::__is_random_access_iterator<_IteratorTypes...>::value;
149157
typedef std::integral_constant<bool, value> type;
150158
};
151159

‎pstl/include/pstl/internal/glue_algorithm_impl.h

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -358,16 +358,15 @@ replace_if(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator
358358
{
359359
using namespace __pstl;
360360
typedef typename iterator_traits<_ForwardIterator>::reference _ElementType;
361-
__internal::__pattern_walk1(
362-
std::forward<_ExecutionPolicy>(__exec), __first, __last,
363-
[&__pred, &__new_value](_ElementType __elem) {
364-
if (__pred(__elem))
365-
{
366-
__elem = __new_value;
367-
}
368-
},
369-
__internal::__is_vectorization_preferred<_ExecutionPolicy, _ForwardIterator>(__exec),
370-
__internal::__is_parallelization_preferred<_ExecutionPolicy, _ForwardIterator>(__exec));
361+
__internal::__pattern_walk1(std::forward<_ExecutionPolicy>(__exec), __first, __last,
362+
[&__pred, &__new_value](_ElementType __elem) {
363+
if (__pred(__elem))
364+
{
365+
__elem = __new_value;
366+
}
367+
},
368+
__internal::__is_vectorization_preferred<_ExecutionPolicy, _ForwardIterator>(__exec),
369+
__internal::__is_parallelization_preferred<_ExecutionPolicy, _ForwardIterator>(__exec));
371370
}
372371

373372
template <class _ExecutionPolicy, class _ForwardIterator, class _Tp>

‎pstl/include/pstl/internal/glue_memory_impl.h

Lines changed: 66 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,11 @@ uninitialized_copy(_ExecutionPolicy&& __exec, _InputIterator __first, _InputIter
4444
__is_parallel);
4545
},
4646
[&]() {
47-
return __internal::__pattern_walk2(
48-
std::forward<_ExecutionPolicy>(__exec), __first, __last, __result,
49-
[](_ReferenceType1 __val1, _ReferenceType2 __val2) {
50-
::new (std::addressof(__val2)) _ValueType2(__val1);
51-
},
52-
__is_vector, __is_parallel);
47+
return __internal::__pattern_walk2(std::forward<_ExecutionPolicy>(__exec), __first, __last, __result,
48+
[](_ReferenceType1 __val1, _ReferenceType2 __val2) {
49+
::new (std::addressof(__val2)) _ValueType2(__val1);
50+
},
51+
__is_vector, __is_parallel);
5352
});
5453
}
5554

@@ -79,12 +78,11 @@ uninitialized_copy_n(_ExecutionPolicy&& __exec, _InputIterator __first, _Size __
7978
__is_parallel);
8079
},
8180
[&]() {
82-
return __internal::__pattern_walk2_n(
83-
std::forward<_ExecutionPolicy>(__exec), __first, __n, __result,
84-
[](_ReferenceType1 __val1, _ReferenceType2 __val2) {
85-
::new (std::addressof(__val2)) _ValueType2(__val1);
86-
},
87-
__is_vector, __is_parallel);
81+
return __internal::__pattern_walk2_n(std::forward<_ExecutionPolicy>(__exec), __first, __n, __result,
82+
[](_ReferenceType1 __val1, _ReferenceType2 __val2) {
83+
::new (std::addressof(__val2)) _ValueType2(__val1);
84+
},
85+
__is_vector, __is_parallel);
8886
});
8987
}
9088

@@ -116,12 +114,11 @@ uninitialized_move(_ExecutionPolicy&& __exec, _InputIterator __first, _InputIter
116114
__is_parallel);
117115
},
118116
[&]() {
119-
return __internal::__pattern_walk2(
120-
std::forward<_ExecutionPolicy>(__exec), __first, __last, __result,
121-
[](_ReferenceType1 __val1, _ReferenceType2 __val2) {
122-
::new (std::addressof(__val2)) _ValueType2(std::move(__val1));
123-
},
124-
__is_vector, __is_parallel);
117+
return __internal::__pattern_walk2(std::forward<_ExecutionPolicy>(__exec), __first, __last, __result,
118+
[](_ReferenceType1 __val1, _ReferenceType2 __val2) {
119+
::new (std::addressof(__val2)) _ValueType2(std::move(__val1));
120+
},
121+
__is_vector, __is_parallel);
125122
});
126123
}
127124

@@ -151,12 +148,11 @@ uninitialized_move_n(_ExecutionPolicy&& __exec, _InputIterator __first, _Size __
151148
__is_parallel);
152149
},
153150
[&]() {
154-
return __internal::__pattern_walk2_n(
155-
std::forward<_ExecutionPolicy>(__exec), __first, __n, __result,
156-
[](_ReferenceType1 __val1, _ReferenceType2 __val2) {
157-
::new (std::addressof(__val2)) _ValueType2(std::move(__val1));
158-
},
159-
__is_vector, __is_parallel);
151+
return __internal::__pattern_walk2_n(std::forward<_ExecutionPolicy>(__exec), __first, __n, __result,
152+
[](_ReferenceType1 __val1, _ReferenceType2 __val2) {
153+
::new (std::addressof(__val2)) _ValueType2(std::move(__val1));
154+
},
155+
__is_vector, __is_parallel);
160156
});
161157
}
162158

@@ -173,22 +169,23 @@ uninitialized_fill(_ExecutionPolicy&& __exec, _ForwardIterator __first, _Forward
173169
const auto __is_parallel = __internal::__is_parallelization_preferred<_ExecutionPolicy, _ForwardIterator>(__exec);
174170
const auto __is_vector = __internal::__is_vectorization_preferred<_ExecutionPolicy, _ForwardIterator>(__exec);
175171

176-
__internal::__invoke_if_else(
177-
std::is_arithmetic<_ValueType>(),
178-
[&]() {
179-
__internal::__pattern_walk_brick(
180-
std::forward<_ExecutionPolicy>(__exec), __first, __last,
181-
[&__value, &__is_vector](_ForwardIterator __begin, _ForwardIterator __end) {
182-
__internal::__brick_fill(__begin, __end, _ValueType(__value), __is_vector);
183-
},
184-
__is_parallel);
185-
},
186-
[&]() {
187-
__internal::__pattern_walk1(
188-
std::forward<_ExecutionPolicy>(__exec), __first, __last,
189-
[&__value](_ReferenceType __val) { ::new (std::addressof(__val)) _ValueType(__value); }, __is_vector,
190-
__is_parallel);
191-
});
172+
__internal::__invoke_if_else(std::is_arithmetic<_ValueType>(),
173+
[&]() {
174+
__internal::__pattern_walk_brick(
175+
std::forward<_ExecutionPolicy>(__exec), __first, __last,
176+
[&__value, &__is_vector](_ForwardIterator __begin, _ForwardIterator __end) {
177+
__internal::__brick_fill(__begin, __end, _ValueType(__value), __is_vector);
178+
},
179+
__is_parallel);
180+
},
181+
[&]() {
182+
__internal::__pattern_walk1(std::forward<_ExecutionPolicy>(__exec), __first,
183+
__last,
184+
[&__value](_ReferenceType __val) {
185+
::new (std::addressof(__val)) _ValueType(__value);
186+
},
187+
__is_vector, __is_parallel);
188+
});
192189
}
193190

194191
template <class _ExecutionPolicy, class _ForwardIterator, class _Size, class _Tp>
@@ -234,9 +231,8 @@ destroy(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __
234231
const auto __is_vector = __internal::__is_vectorization_preferred<_ExecutionPolicy, _ForwardIterator>(__exec);
235232

236233
__internal::__invoke_if_not(std::is_trivially_destructible<_ValueType>(), [&]() {
237-
__internal::__pattern_walk1(
238-
std::forward<_ExecutionPolicy>(__exec), __first, __last, [](_ReferenceType __val) { __val.~_ValueType(); },
239-
__is_vector, __is_parallel);
234+
__internal::__pattern_walk1(std::forward<_ExecutionPolicy>(__exec), __first, __last,
235+
[](_ReferenceType __val) { __val.~_ValueType(); }, __is_vector, __is_parallel);
240236
});
241237
}
242238

@@ -254,9 +250,9 @@ destroy_n(_ExecutionPolicy&& __exec, _ForwardIterator __first, _Size __n)
254250
return __internal::__invoke_if_else(
255251
std::is_trivially_destructible<_ValueType>(), [&]() { return std::next(__first, __n); },
256252
[&]() {
257-
return __internal::__pattern_walk1_n(
258-
std::forward<_ExecutionPolicy>(__exec), __first, __n, [](_ReferenceType __val) { __val.~_ValueType(); },
259-
__is_vector, __is_parallel);
253+
return __internal::__pattern_walk1_n(std::forward<_ExecutionPolicy>(__exec), __first, __n,
254+
[](_ReferenceType __val) { __val.~_ValueType(); }, __is_vector,
255+
__is_parallel);
260256
});
261257
}
262258

@@ -274,9 +270,9 @@ uninitialized_default_construct(_ExecutionPolicy&& __exec, _ForwardIterator __fi
274270
const auto __is_vector = __internal::__is_vectorization_preferred<_ExecutionPolicy, _ForwardIterator>(__exec);
275271

276272
__internal::__invoke_if_not(std::is_trivial<_ValueType>(), [&]() {
277-
__internal::__pattern_walk1(
278-
std::forward<_ExecutionPolicy>(__exec), __first, __last,
279-
[](_ReferenceType __val) { ::new (std::addressof(__val)) _ValueType; }, __is_vector, __is_parallel);
273+
__internal::__pattern_walk1(std::forward<_ExecutionPolicy>(__exec), __first, __last,
274+
[](_ReferenceType __val) { ::new (std::addressof(__val)) _ValueType; }, __is_vector,
275+
__is_parallel);
280276
});
281277
}
282278

@@ -291,13 +287,13 @@ uninitialized_default_construct_n(_ExecutionPolicy&& __exec, _ForwardIterator __
291287
const auto __is_parallel = __internal::__is_parallelization_preferred<_ExecutionPolicy, _ForwardIterator>(__exec);
292288
const auto __is_vector = __internal::__is_vectorization_preferred<_ExecutionPolicy, _ForwardIterator>(__exec);
293289

294-
return __internal::__invoke_if_else(
295-
std::is_trivial<_ValueType>(), [&]() { return std::next(__first, __n); },
296-
[&]() {
297-
return __internal::__pattern_walk1_n(
298-
std::forward<_ExecutionPolicy>(__exec), __first, __n,
299-
[](_ReferenceType __val) { ::new (std::addressof(__val)) _ValueType; }, __is_vector, __is_parallel);
300-
});
290+
return __internal::__invoke_if_else(std::is_trivial<_ValueType>(), [&]() { return std::next(__first, __n); },
291+
[&]() {
292+
return __internal::__pattern_walk1_n(
293+
std::forward<_ExecutionPolicy>(__exec), __first, __n,
294+
[](_ReferenceType __val) { ::new (std::addressof(__val)) _ValueType; },
295+
__is_vector, __is_parallel);
296+
});
301297
}
302298

303299
// [uninitialized.construct.value]
@@ -316,17 +312,16 @@ uninitialized_value_construct(_ExecutionPolicy&& __exec, _ForwardIterator __firs
316312
__internal::__invoke_if_else(
317313
std::is_trivial<_ValueType>(),
318314
[&]() {
319-
__internal::__pattern_walk_brick(
320-
std::forward<_ExecutionPolicy>(__exec), __first, __last,
321-
[__is_vector](_ForwardIterator __begin, _ForwardIterator __end) {
322-
__internal::__brick_fill(__begin, __end, _ValueType(), __is_vector);
323-
},
324-
__is_parallel);
315+
__internal::__pattern_walk_brick(std::forward<_ExecutionPolicy>(__exec), __first, __last,
316+
[__is_vector](_ForwardIterator __begin, _ForwardIterator __end) {
317+
__internal::__brick_fill(__begin, __end, _ValueType(), __is_vector);
318+
},
319+
__is_parallel);
325320
},
326321
[&]() {
327-
__internal::__pattern_walk1(
328-
std::forward<_ExecutionPolicy>(__exec), __first, __last,
329-
[](_ReferenceType __val) { ::new (std::addressof(__val)) _ValueType(); }, __is_vector, __is_parallel);
322+
__internal::__pattern_walk1(std::forward<_ExecutionPolicy>(__exec), __first, __last,
323+
[](_ReferenceType __val) { ::new (std::addressof(__val)) _ValueType(); },
324+
__is_vector, __is_parallel);
330325
});
331326
}
332327

@@ -344,12 +339,12 @@ uninitialized_value_construct_n(_ExecutionPolicy&& __exec, _ForwardIterator __fi
344339
return __internal::__invoke_if_else(
345340
std::is_trivial<_ValueType>(),
346341
[&]() {
347-
return __internal::__pattern_walk_brick_n(
348-
std::forward<_ExecutionPolicy>(__exec), __first, __n,
349-
[__is_vector](_ForwardIterator __begin, _Size __count) {
350-
return __internal::__brick_fill_n(__begin, __count, _ValueType(), __is_vector);
351-
},
352-
__is_parallel);
342+
return __internal::__pattern_walk_brick_n(std::forward<_ExecutionPolicy>(__exec), __first, __n,
343+
[__is_vector](_ForwardIterator __begin, _Size __count) {
344+
return __internal::__brick_fill_n(__begin, __count,
345+
_ValueType(), __is_vector);
346+
},
347+
__is_parallel);
353348
},
354349
[&]() {
355350
return __internal::__pattern_walk1_n(

0 commit comments

Comments
 (0)