Skip to content

Commit

Permalink
Fixup a few things. In particular I removed the test since I don't th…
Browse files Browse the repository at this point in the history
…ink it was testing anything new, and in fact I failed to write a reproducer for the transform_reduce _UnaryResult thing.
  • Loading branch information
ldionne committed Nov 22, 2023
1 parent 56dbdd3 commit bd62875
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 93 deletions.
5 changes: 2 additions & 3 deletions libcxx/include/__algorithm/comp.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#define _LIBCPP___ALGORITHM_COMP_H

#include <__config>
#include <__functional/operations.h>
#include <__type_traits/integral_constant.h>
#include <__type_traits/operation_traits.h>

Expand All @@ -27,8 +26,8 @@ struct __equal_to {
}
};

template <>
struct __desugars_to<__equal_to, equal_to<void> > : true_type {};
template <class _Tp, class _Up>
struct __desugars_to<__equal_tag, __equal_to, _Tp, _Up> : true_type {};

// The definition is required because __less is part of the ABI, but it's empty
// because all comparisons should be transparent.
Expand Down
13 changes: 6 additions & 7 deletions libcxx/include/__algorithm/equal.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include <__config>
#include <__functional/identity.h>
#include <__functional/invoke.h>
#include <__functional/operations.h>
#include <__iterator/distance.h>
#include <__iterator/iterator_traits.h>
#include <__string/constexpr_c_functions.h>
Expand All @@ -42,12 +41,12 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 boo
return true;
}

template < class _Tp,
class _Up,
class _BinaryPredicate,
__enable_if_t<__desugars_to<__equal_tag, _BinaryPredicate, _Tp, _Up>::value && !is_volatile<_Tp>::value &&
!is_volatile<_Up>::value && __libcpp_is_trivially_equality_comparable<_Tp, _Up>::value,
int> = 0>
template <class _Tp,
class _Up,
class _BinaryPredicate,
__enable_if_t<__desugars_to<__equal_tag, _BinaryPredicate, _Tp, _Up>::value && !is_volatile<_Tp>::value &&
!is_volatile<_Up>::value && __libcpp_is_trivially_equality_comparable<_Tp, _Up>::value,
int> = 0>
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
__equal_iter_impl(_Tp* __first1, _Tp* __last1, _Up* __first2, _BinaryPredicate&) {
return std::__constexpr_memcmp_equal(__first1, __first2, __element_count(__last1 - __first1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

#include <__algorithm/pstl_backends/cpu_backends/backend.h>
#include <__config>
#include <__functional/operations.h>
#include <__iterator/concepts.h>
#include <__iterator/iterator_traits.h>
#include <__numeric/transform_reduce.h>
Expand All @@ -30,13 +29,14 @@

_LIBCPP_BEGIN_NAMESPACE_STD

template < typename _DifferenceType,
typename _Tp,
typename _BinaryOperation,
typename _UnaryOperation,
typename _UnaryResult = invoke_result_t<_UnaryOperation, _DifferenceType>,
__enable_if_t<__desugars_to<__plus_tag, _BinaryOperation, _Tp, _UnaryResult>::value && is_arithmetic_v<_Tp>,
int> = 0>
template <typename _DifferenceType,
typename _Tp,
typename _BinaryOperation,
typename _UnaryOperation,
typename _UnaryResult = invoke_result_t<_UnaryOperation, _DifferenceType>,
__enable_if_t<__desugars_to<__plus_tag, _BinaryOperation, _Tp, _UnaryResult>::value && is_arithmetic_v<_Tp> &&
is_arithmetic_v<_UnaryResult>,
int> = 0>
_LIBCPP_HIDE_FROM_ABI _Tp
__simd_transform_reduce(_DifferenceType __n, _Tp __init, _BinaryOperation, _UnaryOperation __f) noexcept {
_PSTL_PRAGMA_SIMD_REDUCTION(+ : __init)
Expand All @@ -45,14 +45,14 @@ __simd_transform_reduce(_DifferenceType __n, _Tp __init, _BinaryOperation, _Unar
return __init;
}

template <
typename _Size,
typename _Tp,
typename _BinaryOperation,
typename _UnaryOperation,
typename _UnaryResult = invoke_result_t<_UnaryOperation, _Size>,
__enable_if_t<!(__desugars_to<__plus_tag, _BinaryOperation, _Tp, _UnaryResult>::value && is_arithmetic_v<_Tp>),
int> = 0>
template <typename _Size,
typename _Tp,
typename _BinaryOperation,
typename _UnaryOperation,
typename _UnaryResult = invoke_result_t<_UnaryOperation, _Size>,
__enable_if_t<!(__desugars_to<__plus_tag, _BinaryOperation, _Tp, _UnaryResult>::value &&
is_arithmetic_v<_Tp> && is_arithmetic_v<_UnaryResult>),
int> = 0>
_LIBCPP_HIDE_FROM_ABI _Tp
__simd_transform_reduce(_Size __n, _Tp __init, _BinaryOperation __binary_op, _UnaryOperation __f) noexcept {
const _Size __block_size = __lane_size / sizeof(_Tp);
Expand Down
13 changes: 4 additions & 9 deletions libcxx/include/__functional/operations.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,13 @@ struct _LIBCPP_TEMPLATE_VIS plus
};
_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(plus);

// For the typed version of plus, we require that the left- and right-hand
// side of the plus operator matches
// The non-transparent std::plus specialization is only equivalent to a raw plus
// operator when we don't perform an implicit conversion when calling it.
template <class _Tp>
struct __desugars_to<__plus_tag, plus<_Tp>, _Tp, _Tp> : true_type {};

#if _LIBCPP_STD_VER >= 14
// In the transparent case, we do not enforce that
template <class _Tp, class _Up>
struct __desugars_to<__plus_tag, plus<void>, _Tp, _Up> : true_type {};
#endif

#if _LIBCPP_STD_VER >= 14
template <>
Expand Down Expand Up @@ -354,16 +351,14 @@ struct _LIBCPP_TEMPLATE_VIS equal_to<void>
};
#endif

// For the typed version of equal_to, we require that the left- and right-hand
// side of the equality operator matches
// The non-transparent std::equal_to specialization is only equivalent to a raw equality
// comparison when we don't perform an implicit conversion when calling it.
template <class _Tp>
struct __desugars_to<__equal_tag, equal_to<_Tp>, _Tp, _Tp> : true_type {};

#if _LIBCPP_STD_VER >= 14
// In the transparent case, we do not enforce that
template <class _Tp, class _Up>
struct __desugars_to<__equal_tag, equal_to<void>, _Tp, _Up> : true_type {};
#endif

#if _LIBCPP_STD_VER >= 14
template <class _Tp = void>
Expand Down
1 change: 0 additions & 1 deletion libcxx/include/__functional/ranges_operations.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include <__concepts/equality_comparable.h>
#include <__concepts/totally_ordered.h>
#include <__config>
#include <__functional/operations.h>
#include <__type_traits/integral_constant.h>
#include <__type_traits/operation_traits.h>
#include <__utility/forward.h>
Expand Down
12 changes: 10 additions & 2 deletions libcxx/include/__type_traits/operation_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,16 @@ _LIBCPP_BEGIN_NAMESPACE_STD
struct __equal_tag {};
struct __plus_tag {};

// In the general case, __desugars_to is false

// This class template is used to determine whether an operation "desugars"
// (or boils down) to a given canonical operation.
//
// For example, `std::equal_to<>`, our internal `std::__equal_to` helper and
// `ranges::equal_to` are all just fancy ways of representing a transparent
// equality operation, so they all desugar to `__equal_tag`.
//
// This is useful to optimize some functions in cases where we know e.g. the
// predicate being passed is actually going to call a builtin operator, or has
// some specific semantics.
template <class _CanonicalTag, class _Operation, class... _Args>
struct __desugars_to : false_type {};

Expand Down

This file was deleted.

0 comments on commit bd62875

Please sign in to comment.