Skip to content
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

[libc++][vector] include formatter only in C++23 #112675

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

atetubou
Copy link
Contributor

@atetubou atetubou requested a review from a team as a code owner October 17, 2024 08:13
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Oct 17, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Oct 17, 2024

@llvm/pr-subscribers-libcxx

Author: Takuto Ikuta (atetubou)

Changes

This is to reduce included header file size in pre C++23 build.

e.g. 2% of total included file coming from formatter_bool.h in chrome build.
https://commondatastorage.googleapis.com/chromium-browser-clang/chrome_includes_2024-10-17_004801.html#view=edges&filter=&sort=asize&reverse=&includer=%5Ethird_party%2Flibc%5C%2B%5C%2B%2Fsrc%2Finclude%2Fvector%24&included=&limit=1000


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

1 Files Affected:

  • (modified) libcxx/include/vector (+5-2)
diff --git a/libcxx/include/vector b/libcxx/include/vector
index dc31f31838264c..93755afdde711c 100644
--- a/libcxx/include/vector
+++ b/libcxx/include/vector
@@ -324,8 +324,6 @@ template<class T, class charT> requires is-vector-bool-reference<T> // Since C++
 #include <__config>
 #include <__debug_utils/sanitizers.h>
 #include <__format/enable_insertable.h>
-#include <__format/formatter.h>
-#include <__format/formatter_bool.h>
 #include <__functional/hash.h>
 #include <__functional/unary_function.h>
 #include <__fwd/vector.h>
@@ -391,6 +389,11 @@ template<class T, class charT> requires is-vector-bool-reference<T> // Since C++
 #include <compare>
 #include <initializer_list>
 
+#if _LIBCPP_STD_VER >= 23
+#  include <__format/formatter.h>
+#  include <__format/formatter_bool.h>
+#endif
+
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #  pragma GCC system_header
 #endif

Copy link
Contributor

@frederick-vs-ja frederick-vs-ja left a comment

Choose a reason for hiding this comment

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

Perhaps we should correspondingly remove related entries in cxx11.csv ~ cxx20.csv in libcxx/test/libcxx/transitive_includes.

@zmodem
Copy link
Collaborator

zmodem commented Oct 17, 2024

There was some discussion of this in https://reviews.llvm.org/D149543 with @mordante

I'm not familiar with the standard's requirements, but if they're only needed only in C++23, making the includes conditional sounds like a good option.

@atetubou
Copy link
Contributor Author

I updated libcxx/test/libcxx/transitive_includes for some C++ versions.

From my understanding, formatter headers are only used from C++23's code for vector<bool> and we don't need to include then in earlier version.

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.

4 participants