Skip to content

Commit f5960c1

Browse files
authored
[libc++][NFC] Make __desugars_to a variable template and rename the header to desugars_to.h (#87337)
This improves compile times and memory usage slightly and removes some boilerplate.
1 parent 5aeb604 commit f5960c1

File tree

11 files changed

+26
-31
lines changed

11 files changed

+26
-31
lines changed

libcxx/include/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,7 @@ set(files
738738
__type_traits/datasizeof.h
739739
__type_traits/decay.h
740740
__type_traits/dependent_type.h
741+
__type_traits/desugars_to.h
741742
__type_traits/disjunction.h
742743
__type_traits/enable_if.h
743744
__type_traits/extent.h
@@ -822,7 +823,6 @@ set(files
822823
__type_traits/nat.h
823824
__type_traits/negation.h
824825
__type_traits/noexcept_move_assign_container.h
825-
__type_traits/operation_traits.h
826826
__type_traits/promote.h
827827
__type_traits/rank.h
828828
__type_traits/remove_all_extents.h

libcxx/include/__algorithm/comp.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
#define _LIBCPP___ALGORITHM_COMP_H
1111

1212
#include <__config>
13-
#include <__type_traits/integral_constant.h>
14-
#include <__type_traits/operation_traits.h>
13+
#include <__type_traits/desugars_to.h>
1514

1615
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1716
# pragma GCC system_header
@@ -27,7 +26,7 @@ struct __equal_to {
2726
};
2827

2928
template <class _Tp, class _Up>
30-
struct __desugars_to<__equal_tag, __equal_to, _Tp, _Up> : true_type {};
29+
inline const bool __desugars_to_v<__equal_tag, __equal_to, _Tp, _Up> = true;
3130

3231
// The definition is required because __less is part of the ABI, but it's empty
3332
// because all comparisons should be transparent.

libcxx/include/__algorithm/equal.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@
1818
#include <__iterator/distance.h>
1919
#include <__iterator/iterator_traits.h>
2020
#include <__string/constexpr_c_functions.h>
21+
#include <__type_traits/desugars_to.h>
2122
#include <__type_traits/enable_if.h>
22-
#include <__type_traits/integral_constant.h>
2323
#include <__type_traits/is_constant_evaluated.h>
2424
#include <__type_traits/is_equality_comparable.h>
2525
#include <__type_traits/is_volatile.h>
26-
#include <__type_traits/operation_traits.h>
2726
#include <__utility/move.h>
2827

2928
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -47,7 +46,7 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 boo
4746
template <class _Tp,
4847
class _Up,
4948
class _BinaryPredicate,
50-
__enable_if_t<__desugars_to<__equal_tag, _BinaryPredicate, _Tp, _Up>::value && !is_volatile<_Tp>::value &&
49+
__enable_if_t<__desugars_to_v<__equal_tag, _BinaryPredicate, _Tp, _Up> && !is_volatile<_Tp>::value &&
5150
!is_volatile<_Up>::value && __libcpp_is_trivially_equality_comparable<_Tp, _Up>::value,
5251
int> = 0>
5352
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
@@ -87,7 +86,7 @@ template <class _Tp,
8786
class _Pred,
8887
class _Proj1,
8988
class _Proj2,
90-
__enable_if_t<__desugars_to<__equal_tag, _Pred, _Tp, _Up>::value && __is_identity<_Proj1>::value &&
89+
__enable_if_t<__desugars_to_v<__equal_tag, _Pred, _Tp, _Up> && __is_identity<_Proj1>::value &&
9190
__is_identity<_Proj2>::value && !is_volatile<_Tp>::value && !is_volatile<_Up>::value &&
9291
__libcpp_is_trivially_equality_comparable<_Tp, _Up>::value,
9392
int> = 0>

libcxx/include/__algorithm/mismatch.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
#include <__algorithm/unwrap_iter.h>
1717
#include <__config>
1818
#include <__functional/identity.h>
19+
#include <__type_traits/desugars_to.h>
1920
#include <__type_traits/invoke.h>
2021
#include <__type_traits/is_constant_evaluated.h>
2122
#include <__type_traits/is_equality_comparable.h>
2223
#include <__type_traits/is_integral.h>
23-
#include <__type_traits/operation_traits.h>
2424
#include <__utility/move.h>
2525
#include <__utility/pair.h>
2626
#include <__utility/unreachable.h>
@@ -59,7 +59,7 @@ template <class _Tp,
5959
class _Pred,
6060
class _Proj1,
6161
class _Proj2,
62-
__enable_if_t<is_integral<_Tp>::value && __desugars_to<__equal_tag, _Pred, _Tp, _Tp>::value &&
62+
__enable_if_t<is_integral<_Tp>::value && __desugars_to_v<__equal_tag, _Pred, _Tp, _Tp> &&
6363
__is_identity<_Proj1>::value && __is_identity<_Proj2>::value,
6464
int> = 0>
6565
_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Tp*, _Tp*>

libcxx/include/__algorithm/pstl_backends/cpu_backends/transform_reduce.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
#include <__iterator/concepts.h>
1515
#include <__iterator/iterator_traits.h>
1616
#include <__numeric/transform_reduce.h>
17+
#include <__type_traits/desugars_to.h>
1718
#include <__type_traits/is_arithmetic.h>
1819
#include <__type_traits/is_execution_policy.h>
19-
#include <__type_traits/operation_traits.h>
2020
#include <__utility/move.h>
2121
#include <new>
2222
#include <optional>
@@ -37,7 +37,7 @@ template <typename _DifferenceType,
3737
typename _BinaryOperation,
3838
typename _UnaryOperation,
3939
typename _UnaryResult = invoke_result_t<_UnaryOperation, _DifferenceType>,
40-
__enable_if_t<__desugars_to<__plus_tag, _BinaryOperation, _Tp, _UnaryResult>::value && is_arithmetic_v<_Tp> &&
40+
__enable_if_t<__desugars_to_v<__plus_tag, _BinaryOperation, _Tp, _UnaryResult> && is_arithmetic_v<_Tp> &&
4141
is_arithmetic_v<_UnaryResult>,
4242
int> = 0>
4343
_LIBCPP_HIDE_FROM_ABI _Tp
@@ -53,8 +53,8 @@ template <typename _Size,
5353
typename _BinaryOperation,
5454
typename _UnaryOperation,
5555
typename _UnaryResult = invoke_result_t<_UnaryOperation, _Size>,
56-
__enable_if_t<!(__desugars_to<__plus_tag, _BinaryOperation, _Tp, _UnaryResult>::value &&
57-
is_arithmetic_v<_Tp> && is_arithmetic_v<_UnaryResult>),
56+
__enable_if_t<!(__desugars_to_v<__plus_tag, _BinaryOperation, _Tp, _UnaryResult> && is_arithmetic_v<_Tp> &&
57+
is_arithmetic_v<_UnaryResult>),
5858
int> = 0>
5959
_LIBCPP_HIDE_FROM_ABI _Tp
6060
__simd_transform_reduce(_Size __n, _Tp __init, _BinaryOperation __binary_op, _UnaryOperation __f) noexcept {

libcxx/include/__functional/operations.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
#include <__config>
1414
#include <__functional/binary_function.h>
1515
#include <__functional/unary_function.h>
16-
#include <__type_traits/integral_constant.h>
17-
#include <__type_traits/operation_traits.h>
16+
#include <__type_traits/desugars_to.h>
1817
#include <__utility/forward.h>
1918

2019
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -41,10 +40,10 @@ _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(plus);
4140
// The non-transparent std::plus specialization is only equivalent to a raw plus
4241
// operator when we don't perform an implicit conversion when calling it.
4342
template <class _Tp>
44-
struct __desugars_to<__plus_tag, plus<_Tp>, _Tp, _Tp> : true_type {};
43+
inline const bool __desugars_to_v<__plus_tag, plus<_Tp>, _Tp, _Tp> = true;
4544

4645
template <class _Tp, class _Up>
47-
struct __desugars_to<__plus_tag, plus<void>, _Tp, _Up> : true_type {};
46+
inline const bool __desugars_to_v<__plus_tag, plus<void>, _Tp, _Up> = true;
4847

4948
#if _LIBCPP_STD_VER >= 14
5049
template <>
@@ -315,11 +314,11 @@ struct _LIBCPP_TEMPLATE_VIS equal_to<void> {
315314
// The non-transparent std::equal_to specialization is only equivalent to a raw equality
316315
// comparison when we don't perform an implicit conversion when calling it.
317316
template <class _Tp>
318-
struct __desugars_to<__equal_tag, equal_to<_Tp>, _Tp, _Tp> : true_type {};
317+
inline const bool __desugars_to_v<__equal_tag, equal_to<_Tp>, _Tp, _Tp> = true;
319318

320319
// In the transparent case, we do not enforce that
321320
template <class _Tp, class _Up>
322-
struct __desugars_to<__equal_tag, equal_to<void>, _Tp, _Up> : true_type {};
321+
inline const bool __desugars_to_v<__equal_tag, equal_to<void>, _Tp, _Up> = true;
323322

324323
#if _LIBCPP_STD_VER >= 14
325324
template <class _Tp = void>

libcxx/include/__functional/ranges_operations.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
#include <__concepts/equality_comparable.h>
1414
#include <__concepts/totally_ordered.h>
1515
#include <__config>
16-
#include <__type_traits/integral_constant.h>
17-
#include <__type_traits/operation_traits.h>
16+
#include <__type_traits/desugars_to.h>
1817
#include <__utility/forward.h>
1918

2019
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -98,7 +97,7 @@ struct greater_equal {
9897
// For ranges we do not require that the types on each side of the equality
9998
// operator are of the same type
10099
template <class _Tp, class _Up>
101-
struct __desugars_to<__equal_tag, ranges::equal_to, _Tp, _Up> : true_type {};
100+
inline const bool __desugars_to_v<__equal_tag, ranges::equal_to, _Tp, _Up> = true;
102101

103102
#endif // _LIBCPP_STD_VER >= 20
104103

libcxx/include/__numeric/pstl_transform_reduce.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ _LIBCPP_HIDE_FROM_ABI _Tp transform_reduce(
8787
}
8888

8989
// This overload doesn't get a customization point because it's trivial to detect (through e.g.
90-
// __desugars_to) when specializing the more general variant, which should always be preferred
90+
// __desugars_to_v) when specializing the more general variant, which should always be preferred
9191
template <class _ExecutionPolicy,
9292
class _ForwardIterator1,
9393
class _ForwardIterator2,

libcxx/include/__type_traits/operation_traits.h renamed to libcxx/include/__type_traits/desugars_to.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#ifndef _LIBCPP___TYPE_TRAITS_OPERATION_TRAITS_H
10-
#define _LIBCPP___TYPE_TRAITS_OPERATION_TRAITS_H
9+
#ifndef _LIBCPP___TYPE_TRAITS_DESUGARS_TO_H
10+
#define _LIBCPP___TYPE_TRAITS_DESUGARS_TO_H
1111

1212
#include <__config>
13-
#include <__type_traits/integral_constant.h>
1413

1514
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1615
# pragma GCC system_header
@@ -33,8 +32,8 @@ struct __plus_tag {};
3332
// predicate being passed is actually going to call a builtin operator, or has
3433
// some specific semantics.
3534
template <class _CanonicalTag, class _Operation, class... _Args>
36-
struct __desugars_to : false_type {};
35+
inline const bool __desugars_to_v = false;
3736

3837
_LIBCPP_END_NAMESPACE_STD
3938

40-
#endif // _LIBCPP___TYPE_TRAITS_OPERATION_TRAITS_H
39+
#endif // _LIBCPP___TYPE_TRAITS_DESUGARS_TO_H

libcxx/include/libcxx.imp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,7 @@
734734
{ include: [ "<__type_traits/datasizeof.h>", "private", "<type_traits>", "public" ] },
735735
{ include: [ "<__type_traits/decay.h>", "private", "<type_traits>", "public" ] },
736736
{ include: [ "<__type_traits/dependent_type.h>", "private", "<type_traits>", "public" ] },
737+
{ include: [ "<__type_traits/desugars_to.h>", "private", "<type_traits>", "public" ] },
737738
{ include: [ "<__type_traits/disjunction.h>", "private", "<type_traits>", "public" ] },
738739
{ include: [ "<__type_traits/enable_if.h>", "private", "<type_traits>", "public" ] },
739740
{ include: [ "<__type_traits/extent.h>", "private", "<type_traits>", "public" ] },
@@ -818,7 +819,6 @@
818819
{ include: [ "<__type_traits/nat.h>", "private", "<type_traits>", "public" ] },
819820
{ include: [ "<__type_traits/negation.h>", "private", "<type_traits>", "public" ] },
820821
{ include: [ "<__type_traits/noexcept_move_assign_container.h>", "private", "<type_traits>", "public" ] },
821-
{ include: [ "<__type_traits/operation_traits.h>", "private", "<type_traits>", "public" ] },
822822
{ include: [ "<__type_traits/promote.h>", "private", "<type_traits>", "public" ] },
823823
{ include: [ "<__type_traits/rank.h>", "private", "<type_traits>", "public" ] },
824824
{ include: [ "<__type_traits/remove_all_extents.h>", "private", "<type_traits>", "public" ] },

libcxx/include/module.modulemap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1867,6 +1867,7 @@ module std_private_type_traits_decay [system
18671867
export std_private_type_traits_add_pointer
18681868
}
18691869
module std_private_type_traits_dependent_type [system] { header "__type_traits/dependent_type.h" }
1870+
module std_private_type_traits_desugars_to [system] { header "__type_traits/desugars_to.h" }
18701871
module std_private_type_traits_disjunction [system] { header "__type_traits/disjunction.h" }
18711872
module std_private_type_traits_enable_if [system] { header "__type_traits/enable_if.h" }
18721873
module std_private_type_traits_extent [system] { header "__type_traits/extent.h" }
@@ -2017,7 +2018,6 @@ module std_private_type_traits_maybe_const [system
20172018
module std_private_type_traits_nat [system] { header "__type_traits/nat.h" }
20182019
module std_private_type_traits_negation [system] { header "__type_traits/negation.h" }
20192020
module std_private_type_traits_noexcept_move_assign_container [system] { header "__type_traits/noexcept_move_assign_container.h" }
2020-
module std_private_type_traits_operation_traits [system] { header "__type_traits/operation_traits.h" }
20212021
module std_private_type_traits_promote [system] { header "__type_traits/promote.h" }
20222022
module std_private_type_traits_rank [system] { header "__type_traits/rank.h" }
20232023
module std_private_type_traits_remove_all_extents [system] { header "__type_traits/remove_all_extents.h" }

0 commit comments

Comments
 (0)