[libcxx-commits] [libcxx] 0106ae3 - [libc++] Use _Lazy in tuple constructors
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Sep 26 06:24:14 PDT 2023
Author: Louis Dionne
Date: 2023-09-26T09:24:05-04:00
New Revision: 0106ae3cce01b88a87acfa9cae823ed4990b907e
URL: https://github.com/llvm/llvm-project/commit/0106ae3cce01b88a87acfa9cae823ed4990b907e
DIFF: https://github.com/llvm/llvm-project/commit/0106ae3cce01b88a87acfa9cae823ed4990b907e.diff
LOG: [libc++] Use _Lazy in tuple constructors
This reduces the number of instantiations and also avoid blowing up
past the fold-expression limit of Clang.
This is NOT a general statement that we should strive to stay within
Clang's (sometimes way too small) limits, however in this case the
change will reduce the number of template instantiations while at the
same time doing that, which is good.
Differential Revision: https://reviews.llvm.org/D132509
Added:
Modified:
libcxx/include/tuple
libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/recursion_depth.pass.cpp
Removed:
################################################################################
diff --git a/libcxx/include/tuple b/libcxx/include/tuple
index e5b7a81c9812185..e7fc1e28fb6e034 100644
--- a/libcxx/include/tuple
+++ b/libcxx/include/tuple
@@ -883,13 +883,13 @@ public:
template <class... _Up, enable_if_t<
_EnableCtorFromUTypesTuple<tuple<_Up...>&>::value>* = nullptr>
_LIBCPP_HIDE_FROM_ABI constexpr
- explicit(!(is_convertible_v<_Up&, _Tp> && ...))
+ explicit(!_Lazy<_And, is_convertible<_Up&, _Tp>...>::value)
tuple(tuple<_Up...>& __t) : __base_(__t) {}
template <class _Alloc, class... _Up, enable_if_t<
_EnableCtorFromUTypesTuple<tuple<_Up...>&>::value>* = nullptr>
_LIBCPP_HIDE_FROM_ABI constexpr
- explicit(!(is_convertible_v<_Up&, _Tp> && ...))
+ explicit(!_Lazy<_And, is_convertible<_Up&, _Tp>...>::value)
tuple(allocator_arg_t, const _Alloc& __alloc, tuple<_Up...>& __t) : __base_(allocator_arg_t(), __alloc, __t) {}
#endif // _LIBCPP_STD_VER >= 23
@@ -947,13 +947,13 @@ public:
template <class... _Up, enable_if_t<
_EnableCtorFromUTypesTuple<const tuple<_Up...>&&>::value>* = nullptr>
_LIBCPP_HIDE_FROM_ABI constexpr
- explicit(!(is_convertible_v<const _Up&&, _Tp> && ...))
+ explicit(!_Lazy<_And, is_convertible<const _Up&&, _Tp>...>::value)
tuple(const tuple<_Up...>&& __t) : __base_(std::move(__t)) {}
template <class _Alloc, class... _Up, enable_if_t<
_EnableCtorFromUTypesTuple<const tuple<_Up...>&&>::value>* = nullptr>
_LIBCPP_HIDE_FROM_ABI constexpr
- explicit(!(is_convertible_v<const _Up&&, _Tp> && ...))
+ explicit(!_Lazy<_And, is_convertible<const _Up&&, _Tp>...>::value)
tuple(allocator_arg_t, const _Alloc& __alloc, const tuple<_Up...>&& __t)
: __base_(allocator_arg_t(), __alloc, std::move(__t)) {}
#endif // _LIBCPP_STD_VER >= 23
diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/recursion_depth.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/recursion_depth.pass.cpp
index df10df84229f32b..57d37079c9f0c68 100644
--- a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/recursion_depth.pass.cpp
+++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/recursion_depth.pass.cpp
@@ -9,21 +9,41 @@
// UNSUPPORTED: c++03, c++11
// Make sure that we don't blow up the template instantiation recursion depth
-// for tuples of size <= 1024.
+// for tuples of size <= 512.
#include <tuple>
#include <cassert>
#include <utility>
+#include "test_macros.h"
+
template <std::size_t... I>
constexpr void CreateTuple(std::index_sequence<I...>) {
- std::tuple<decltype(I)...> tuple(I...);
- assert(std::get<0>(tuple) == 0);
- assert(std::get<sizeof...(I)-1>(tuple) == sizeof...(I)-1);
+ using LargeTuple = std::tuple<std::integral_constant<std::size_t, I>...>;
+ using TargetTuple = std::tuple<decltype(I)...>;
+ LargeTuple tuple(std::integral_constant<std::size_t, I>{}...);
+ assert(std::get<0>(tuple).value == 0);
+ assert(std::get<sizeof...(I)-1>(tuple).value == sizeof...(I)-1);
+
+ TargetTuple t1 = tuple; // converting copy constructor from &
+ TargetTuple t2 = static_cast<LargeTuple const&>(tuple); // converting copy constructor from const&
+ TargetTuple t3 = std::move(tuple); // converting rvalue constructor
+ TargetTuple t4 = static_cast<LargeTuple const&&>(tuple); // converting const rvalue constructor
+ TargetTuple t5; // default constructor
+ (void)t1; (void)t2; (void)t3; (void)t4; (void)t5;
+
+#if TEST_STD_VER >= 20
+ t1 = tuple; // converting assignment from &
+ t1 = static_cast<LargeTuple const&>(tuple); // converting assignment from const&
+ t1 = std::move(tuple); // converting assignment from &&
+ t1 = static_cast<LargeTuple const&&>(tuple); // converting assignment from const&&
+ swap(t1, t2); // swap
+#endif
+ // t1 == tuple; // comparison does not work yet (we blow the constexpr stack)
}
constexpr bool test() {
- CreateTuple(std::make_index_sequence<1024>{});
+ CreateTuple(std::make_index_sequence<512>{});
return true;
}
More information about the libcxx-commits
mailing list