Skip to content

[libc++] Remove <tuple> include from <__format/concepts.h> #80214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 14, 2024

Conversation

philnik777
Copy link
Contributor

@philnik777 philnik777 commented Jan 31, 2024

This also moves tuple_size_v into tuple_size as a drive-by.

@philnik777 philnik777 requested a review from a team as a code owner January 31, 2024 23:20
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Jan 31, 2024
@llvmbot
Copy link
Member

llvmbot commented Jan 31, 2024

@llvm/pr-subscribers-libcxx

Author: Nikolas Klauser (philnik777)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/80214.diff

5 Files Affected:

  • (modified) libcxx/include/__format/concepts.h (+3-1)
  • (modified) libcxx/include/__tuple/tuple_size.h (+6-1)
  • (modified) libcxx/include/tuple (-3)
  • (modified) libcxx/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_v.verify.cpp (+1-1)
  • (modified) libcxx/test/tools/clang_tidy_checks/CMakeLists.txt (+1-1)
diff --git a/libcxx/include/__format/concepts.h b/libcxx/include/__format/concepts.h
index 299c5f40ee35b..37181d837ebf2 100644
--- a/libcxx/include/__format/concepts.h
+++ b/libcxx/include/__format/concepts.h
@@ -15,10 +15,12 @@
 #include <__config>
 #include <__format/format_fwd.h>
 #include <__format/format_parse_context.h>
+#include <__fwd/tuple.h>
+#include <__tuple/tuple_size.h>
 #include <__type_traits/is_specialization.h>
 #include <__type_traits/remove_const.h>
+#include <__type_traits/remove_reference.h>
 #include <__utility/pair.h>
-#include <tuple>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #  pragma GCC system_header
diff --git a/libcxx/include/__tuple/tuple_size.h b/libcxx/include/__tuple/tuple_size.h
index b8320106fb269..18a17fd4d5878 100644
--- a/libcxx/include/__tuple/tuple_size.h
+++ b/libcxx/include/__tuple/tuple_size.h
@@ -43,7 +43,7 @@ struct _LIBCPP_TEMPLATE_VIS tuple_size<__enable_if_tuple_size_imp< volatile _Tp,
 
 template <class _Tp>
 struct _LIBCPP_TEMPLATE_VIS
-    tuple_size<__enable_if_tuple_size_imp< const volatile _Tp, integral_constant<size_t, sizeof(tuple_size<_Tp>)>>>
+tuple_size<__enable_if_tuple_size_imp<const volatile _Tp, integral_constant<size_t, sizeof(tuple_size<_Tp>)>>>
     : public integral_constant<size_t, tuple_size<_Tp>::value> {};
 
 #else
@@ -63,6 +63,11 @@ struct _LIBCPP_TEMPLATE_VIS tuple_size<tuple<_Tp...> > : public integral_constan
 template <class... _Tp>
 struct _LIBCPP_TEMPLATE_VIS tuple_size<__tuple_types<_Tp...> > : public integral_constant<size_t, sizeof...(_Tp)> {};
 
+#  if _LIBCPP_STD_VER >= 17
+template <class _Tp>
+inline constexpr size_t tuple_size_v = tuple_size<_Tp>::value;
+#  endif
+
 #endif // _LIBCPP_CXX03_LANG
 
 _LIBCPP_END_NAMESPACE_STD
diff --git a/libcxx/include/tuple b/libcxx/include/tuple
index 0e5f0b4831b41..a293f978c9f6f 100644
--- a/libcxx/include/tuple
+++ b/libcxx/include/tuple
@@ -1410,9 +1410,6 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_T1, _T2>::pair(
       second(std::forward<_Args2>(std::get<_I2>(__second_args))...) {}
 
 #  if _LIBCPP_STD_VER >= 17
-template <class _Tp>
-inline constexpr size_t tuple_size_v = tuple_size<_Tp>::value;
-
 #    define _LIBCPP_NOEXCEPT_RETURN(...)                                                                               \
       noexcept(noexcept(__VA_ARGS__)) { return __VA_ARGS__; }
 
diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_v.verify.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_v.verify.cpp
index 7570230b4b074..573d973b706c2 100644
--- a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_v.verify.cpp
+++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_v.verify.cpp
@@ -20,5 +20,5 @@ void f() {
     (void)std::tuple_size_v<std::tuple<> &>; // expected-note {{requested here}}
     (void)std::tuple_size_v<int>; // expected-note {{requested here}}
     (void)std::tuple_size_v<std::tuple<>*>; // expected-note {{requested here}}
-    // expected-error@tuple:* 3 {{implicit instantiation of undefined template}}
+    // expected-error@*:* 3 {{implicit instantiation of undefined template}}
 }
diff --git a/libcxx/test/tools/clang_tidy_checks/CMakeLists.txt b/libcxx/test/tools/clang_tidy_checks/CMakeLists.txt
index 978e709521652..ab448061f52dc 100644
--- a/libcxx/test/tools/clang_tidy_checks/CMakeLists.txt
+++ b/libcxx/test/tools/clang_tidy_checks/CMakeLists.txt
@@ -5,7 +5,7 @@
 set(LLVM_DIR_SAVE ${LLVM_DIR})
 set(Clang_DIR_SAVE ${Clang_DIR})
 
-find_package(Clang 18)
+find_package(Clang 19)
 if (NOT Clang_FOUND)
   find_package(Clang 17)
 endif()

Copy link

github-actions bot commented Jan 31, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@philnik777 philnik777 force-pushed the remove_tuple_include branch 3 times, most recently from 8d45507 to e10abb8 Compare February 1, 2024 11:47
@@ -86,7 +86,6 @@ chrono sstream
chrono stdexcept
chrono string
chrono string_view
chrono tuple
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK we wanted to keep our transitive set stable. Maybe we should discuss this policy during a monthly meeting. Based on the several remarks on the size by the Chromium team and recently #80196 I think we should revise our header stability policy or at least have a plan how to remove transitive includes.

@vitaut recently blogged about this too, and _LIBCPP_REMOVE_TRANSITIVE_INCLUDES does not seem to be well known.

@ldionne can you put this on the agenda?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Until now we've only kept the includes up to C++20 stable. C++23 was always fair game. I agree that we should rethink our policy on this, since the amount of transitive includes that we could avoid has become massive. I'm currently also working on a patch to reduce the transitive includes further by including things in the top level headers by version.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Until now we've only kept the includes up to C++20 stable. C++23 was always fair game. I agree that we should rethink our policy on this, since the amount of transitive includes that we could avoid has become massive.

I know, but at some point it was said only the C++ development version is fair game, which would mean C++26. Hence the proposal to discuss this. I was already considering to put it on the agenda after a private conversation with Victor.

I'm currently also working on a patch to reduce the transitive includes further by including things in the top level headers by version.

The last time I had a patch to improve the transitive includes by #ifdef-ing it got a lukewarm response. So nice to hear the response now is better.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the last monthly meeting we didn't declare C++23 includes frozen.

@@ -2972,6 +2972,7 @@ _LIBCPP_POP_MACROS
# include <atomic>
# include <concepts>
# include <cstdlib>
# include <tuple>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the tuple dependency for C++20 and now we need to keep it for C++11 - C++17 where tuple was never used. IMO a good reason to discuss our policy.

@philnik777 philnik777 force-pushed the remove_tuple_include branch 3 times, most recently from d34138a to 9e46767 Compare March 9, 2024 15:16
@philnik777 philnik777 force-pushed the remove_tuple_include branch from 9e46767 to 7e1a4ed Compare March 11, 2024 12:49
Copy link
Member

@mordante mordante left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! modulo a nit.

Comment on lines +66 to +70
# if _LIBCPP_STD_VER >= 17
template <class _Tp>
inline constexpr size_t tuple_size_v = tuple_size<_Tp>::value;
# endif

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you mention this in the description?

@philnik777 philnik777 merged commit 4528c44 into llvm:main Mar 14, 2024
@philnik777 philnik777 deleted the remove_tuple_include branch March 14, 2024 11:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants