[libcxx-commits] [libcxx] [libc++] Add missing headers to the modulemap (PR #71127)

via libcxx-commits libcxx-commits at lists.llvm.org
Thu Nov 2 16:35:16 PDT 2023


https://github.com/philnik777 created https://github.com/llvm/llvm-project/pull/71127

I don't know when, but at some point we lost test coverage to ensue that
all the headers are in the modulemap. This adds a test to make sure all
the headers (excluding a few which shouldn't be part of the modulemap)
are at least mentioned. This also fixes a few headers which bit-rotted
while we were missing the coverage.


>From badbdee3a743548ca45ec8d7513dae77df4e74ea Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Fri, 3 Nov 2023 00:32:41 +0100
Subject: [PATCH] [libc++] Add missing headers to the modulemap

I don't know when, but at some point we lost test coverage to ensue that
all the headers are in the modulemap. This adds a test to make sure all
the headers (excluding a few which shouldn't be part of the modulemap)
are at least mentioned. This also fixes a few headers which bit-rotted
while we were missing the coverage.
---
 libcxx/include/__algorithm/pstl_move.h        |  1 +
 libcxx/include/experimental/__simd/abi_tag.h  |  5 +-
 .../include/experimental/__simd/aligned_tag.h |  3 +-
 .../include/experimental/__simd/declaration.h |  3 ++
 .../__simd/internal_declaration.h             |  7 +++
 .../include/experimental/__simd/reference.h   |  4 ++
 libcxx/include/experimental/__simd/scalar.h   |  5 ++
 libcxx/include/experimental/__simd/simd.h     | 10 +++-
 .../include/experimental/__simd/simd_mask.h   |  9 +++-
 libcxx/include/experimental/__simd/traits.h   | 17 ++-----
 libcxx/include/experimental/__simd/utility.h  |  2 +
 libcxx/include/experimental/__simd/vec_ext.h  |  6 +++
 libcxx/include/module.modulemap.in            | 21 ++++++++-
 libcxx/test/libcxx/headers_in_modulemap.sh.py | 47 +++++++++++++++++++
 14 files changed, 120 insertions(+), 20 deletions(-)
 create mode 100644 libcxx/test/libcxx/headers_in_modulemap.sh.py

diff --git a/libcxx/include/__algorithm/pstl_move.h b/libcxx/include/__algorithm/pstl_move.h
index 775dc2604931309..52baab57591e268 100644
--- a/libcxx/include/__algorithm/pstl_move.h
+++ b/libcxx/include/__algorithm/pstl_move.h
@@ -10,6 +10,7 @@
 #define _LIBCPP___ALGORITHM_PSTL_MOVE_H
 
 #include <__algorithm/copy_n.h>
+#include <__algorithm/pstl_backend.h>
 #include <__algorithm/pstl_frontend_dispatch.h>
 #include <__algorithm/pstl_transform.h>
 #include <__config>
diff --git a/libcxx/include/experimental/__simd/abi_tag.h b/libcxx/include/experimental/__simd/abi_tag.h
index a9d51c0683b1dc8..cec5be65ce5c217 100644
--- a/libcxx/include/experimental/__simd/abi_tag.h
+++ b/libcxx/include/experimental/__simd/abi_tag.h
@@ -10,8 +10,9 @@
 #ifndef _LIBCPP_EXPERIMENTAL___SIMD_ABI_TAG_H
 #define _LIBCPP_EXPERIMENTAL___SIMD_ABI_TAG_H
 
-#include <experimental/__simd/scalar.h>
-#include <experimental/__simd/vec_ext.h>
+#include <cstddef>
+#include <experimental/__config>
+#include <experimental/__simd/internal_declaration.h>
 
 #if _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL)
 
diff --git a/libcxx/include/experimental/__simd/aligned_tag.h b/libcxx/include/experimental/__simd/aligned_tag.h
index d3816ae1b0717d7..d216a21c073f3a3 100644
--- a/libcxx/include/experimental/__simd/aligned_tag.h
+++ b/libcxx/include/experimental/__simd/aligned_tag.h
@@ -12,7 +12,8 @@
 
 #include <__bit/bit_ceil.h>
 #include <__memory/assume_aligned.h>
-#include <cstdint>
+#include <cstddef>
+#include <experimental/__config>
 
 #if _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL)
 
diff --git a/libcxx/include/experimental/__simd/declaration.h b/libcxx/include/experimental/__simd/declaration.h
index 747f87be63e535b..065faeaec3841f9 100644
--- a/libcxx/include/experimental/__simd/declaration.h
+++ b/libcxx/include/experimental/__simd/declaration.h
@@ -10,6 +10,9 @@
 #ifndef _LIBCPP_EXPERIMENTAL___SIMD_DECLARATION_H
 #define _LIBCPP_EXPERIMENTAL___SIMD_DECLARATION_H
 
+#include <experimental/__config>
+#include <experimental/__simd/abi_tag.h>
+
 #if _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL)
 
 _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL
diff --git a/libcxx/include/experimental/__simd/internal_declaration.h b/libcxx/include/experimental/__simd/internal_declaration.h
index 294b54d63bb5d9f..9ad1ad1ae3192fd 100644
--- a/libcxx/include/experimental/__simd/internal_declaration.h
+++ b/libcxx/include/experimental/__simd/internal_declaration.h
@@ -10,10 +10,17 @@
 #ifndef _LIBCPP_EXPERIMENTAL___SIMD_INTERNAL_DECLARATION_H
 #define _LIBCPP_EXPERIMENTAL___SIMD_INTERNAL_DECLARATION_H
 
+#include <experimental/__config>
+
 #if _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL)
 
 _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL
 inline namespace parallelism_v2 {
+namespace simd_abi {
+template <int>
+struct __vec_ext;
+struct __scalar;
+} // namespace simd_abi
 
 template <class _Tp, class _Abi>
 struct __simd_storage;
diff --git a/libcxx/include/experimental/__simd/reference.h b/libcxx/include/experimental/__simd/reference.h
index 8c58d24f2f2dc42..7efbba96ec71b13 100644
--- a/libcxx/include/experimental/__simd/reference.h
+++ b/libcxx/include/experimental/__simd/reference.h
@@ -11,6 +11,10 @@
 #define _LIBCPP_EXPERIMENTAL___SIMD_REFERENCE_H
 
 #include <__type_traits/is_assignable.h>
+#include <__type_traits/is_same.h>
+#include <__utility/forward.h>
+#include <cstddef>
+#include <experimental/__config>
 #include <experimental/__simd/utility.h>
 
 #if _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL)
diff --git a/libcxx/include/experimental/__simd/scalar.h b/libcxx/include/experimental/__simd/scalar.h
index 479809392f81539..53fa1c29f374ca9 100644
--- a/libcxx/include/experimental/__simd/scalar.h
+++ b/libcxx/include/experimental/__simd/scalar.h
@@ -11,7 +11,9 @@
 #define _LIBCPP_EXPERIMENTAL___SIMD_SCALAR_H
 
 #include <cstddef>
+#include <experimental/__config>
 #include <experimental/__simd/internal_declaration.h>
+#include <experimental/__simd/traits.h>
 
 #if _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL)
 
@@ -23,6 +25,9 @@ struct __scalar {
 };
 } // namespace simd_abi
 
+template <>
+inline constexpr bool is_abi_tag_v<simd_abi::__scalar> = true;
+
 template <class _Tp>
 struct __simd_storage<_Tp, simd_abi::__scalar> {
   _Tp __data;
diff --git a/libcxx/include/experimental/__simd/simd.h b/libcxx/include/experimental/__simd/simd.h
index 29a566608603d65..d08ff010c833ff4 100644
--- a/libcxx/include/experimental/__simd/simd.h
+++ b/libcxx/include/experimental/__simd/simd.h
@@ -11,12 +11,15 @@
 #define _LIBCPP_EXPERIMENTAL___SIMD_SIMD_H
 
 #include <__type_traits/remove_cvref.h>
+#include <__utility/forward.h>
+#include <cstddef>
+#include <experimental/__config>
 #include <experimental/__simd/abi_tag.h>
 #include <experimental/__simd/declaration.h>
+#include <experimental/__simd/internal_declaration.h>
 #include <experimental/__simd/reference.h>
-#include <experimental/__simd/scalar.h>
 #include <experimental/__simd/traits.h>
-#include <experimental/__simd/vec_ext.h>
+#include <experimental/__simd/utility.h>
 
 #if _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL)
 
@@ -56,6 +59,9 @@ class simd {
   _LIBCPP_HIDE_FROM_ABI value_type operator[](size_t __i) const noexcept { return __s_.__get(__i); }
 };
 
+template <class _Tp, class _Abi>
+inline constexpr bool is_simd_v<simd<_Tp, _Abi>> = true;
+
 template <class _Tp>
 using native_simd = simd<_Tp, simd_abi::native<_Tp>>;
 
diff --git a/libcxx/include/experimental/__simd/simd_mask.h b/libcxx/include/experimental/__simd/simd_mask.h
index 2e47b678913f851..c6f2d9a1a51f801 100644
--- a/libcxx/include/experimental/__simd/simd_mask.h
+++ b/libcxx/include/experimental/__simd/simd_mask.h
@@ -10,11 +10,13 @@
 #ifndef _LIBCPP_EXPERIMENTAL___SIMD_SIMD_MASK_H
 #define _LIBCPP_EXPERIMENTAL___SIMD_SIMD_MASK_H
 
+#include <cstddef>
+#include <experimental/__config>
 #include <experimental/__simd/abi_tag.h>
 #include <experimental/__simd/declaration.h>
+#include <experimental/__simd/internal_declaration.h>
 #include <experimental/__simd/reference.h>
-#include <experimental/__simd/scalar.h>
-#include <experimental/__simd/vec_ext.h>
+#include <experimental/__simd/traits.h>
 
 #if _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL)
 
@@ -48,6 +50,9 @@ class simd_mask {
   _LIBCPP_HIDE_FROM_ABI value_type operator[](size_t __i) const noexcept { return __s_.__get(__i); }
 };
 
+template <class _Tp, class _Abi>
+inline constexpr bool is_simd_mask_v<simd_mask<_Tp, _Abi>> = true;
+
 template <class _Tp>
 using native_simd_mask = simd_mask<_Tp, simd_abi::native<_Tp>>;
 
diff --git a/libcxx/include/experimental/__simd/traits.h b/libcxx/include/experimental/__simd/traits.h
index db6ecfa98c86480..9b4abe9d0c232e8 100644
--- a/libcxx/include/experimental/__simd/traits.h
+++ b/libcxx/include/experimental/__simd/traits.h
@@ -10,9 +10,14 @@
 #ifndef _LIBCPP_EXPERIMENTAL___SIMD_TRAITS_H
 #define _LIBCPP_EXPERIMENTAL___SIMD_TRAITS_H
 
+#include <__type_traits/integral_constant.h>
+#include <__type_traits/is_same.h>
+#include <cstddef>
+#include <experimental/__config>
 #include <experimental/__simd/abi_tag.h>
 #include <experimental/__simd/aligned_tag.h>
 #include <experimental/__simd/declaration.h>
+#include <experimental/__simd/internal_declaration.h>
 #include <experimental/__simd/utility.h>
 
 #if _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL)
@@ -24,30 +29,18 @@ inline namespace parallelism_v2 {
 template <class _Tp>
 inline constexpr bool is_abi_tag_v = false;
 
-template <>
-inline constexpr bool is_abi_tag_v<simd_abi::__scalar> = true;
-
-template <int _Np>
-inline constexpr bool is_abi_tag_v<simd_abi::__vec_ext<_Np>> = _Np > 0 && _Np <= 32;
-
 template <class _Tp>
 struct is_abi_tag : bool_constant<is_abi_tag_v<_Tp>> {};
 
 template <class _Tp>
 inline constexpr bool is_simd_v = false;
 
-template <class _Tp, class _Abi>
-inline constexpr bool is_simd_v<simd<_Tp, _Abi>> = true;
-
 template <class _Tp>
 struct is_simd : bool_constant<is_simd_v<_Tp>> {};
 
 template <class _Tp>
 inline constexpr bool is_simd_mask_v = false;
 
-template <class _Tp, class _Abi>
-inline constexpr bool is_simd_mask_v<simd_mask<_Tp, _Abi>> = true;
-
 template <class _Tp>
 struct is_simd_mask : bool_constant<is_simd_mask_v<_Tp>> {};
 
diff --git a/libcxx/include/experimental/__simd/utility.h b/libcxx/include/experimental/__simd/utility.h
index 847d006629c8d3b..708fa3d8f72cef8 100644
--- a/libcxx/include/experimental/__simd/utility.h
+++ b/libcxx/include/experimental/__simd/utility.h
@@ -20,7 +20,9 @@
 #include <__type_traits/void_t.h>
 #include <__utility/declval.h>
 #include <__utility/integer_sequence.h>
+#include <cstddef>
 #include <cstdint>
+#include <experimental/__config>
 #include <limits>
 
 _LIBCPP_PUSH_MACROS
diff --git a/libcxx/include/experimental/__simd/vec_ext.h b/libcxx/include/experimental/__simd/vec_ext.h
index 4b23bfe384477ed..baaeda6a7401a41 100644
--- a/libcxx/include/experimental/__simd/vec_ext.h
+++ b/libcxx/include/experimental/__simd/vec_ext.h
@@ -12,8 +12,11 @@
 
 #include <__bit/bit_ceil.h>
 #include <__utility/forward.h>
+#include <__utility/integer_sequence.h>
 #include <cstddef>
+#include <experimental/__config>
 #include <experimental/__simd/internal_declaration.h>
+#include <experimental/__simd/traits.h>
 #include <experimental/__simd/utility.h>
 
 #if _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL)
@@ -27,6 +30,9 @@ struct __vec_ext {
 };
 } // namespace simd_abi
 
+template <int _Np>
+inline constexpr bool is_abi_tag_v<simd_abi::__vec_ext<_Np>> = _Np > 0 && _Np <= 32;
+
 template <class _Tp, int _Np>
 struct __simd_storage<_Tp, simd_abi::__vec_ext<_Np>> {
   _Tp __data __attribute__((__vector_size__(std::__bit_ceil((sizeof(_Tp) * _Np)))));
diff --git a/libcxx/include/module.modulemap.in b/libcxx/include/module.modulemap.in
index f447b2fa0a0ce94..04efa8941d016b7 100644
--- a/libcxx/include/module.modulemap.in
+++ b/libcxx/include/module.modulemap.in
@@ -547,6 +547,18 @@ module std_experimental [system] {
     export *
   }
   module simd {
+    module abi_tag              { private header "experimental/__simd/abi_tag.h" }
+    module aligned_tag          { private header "experimental/__simd/aligned_tag.h" }
+    module declaration          { private header "experimental/__simd/declaration.h" }
+    module internal_declaration { private header "experimental/__simd/internal_declaration.h" }
+    module reference            { private header "experimental/__simd/reference.h" }
+    module scalar               { private header "experimental/__simd/scalar.h" }
+    module simd                 { private header "experimental/__simd/simd.h" }
+    module simd_mask            { private header "experimental/__simd/simd_mask.h" }
+    module traits               { private header "experimental/__simd/traits.h" }
+    module utility              { private header "experimental/__simd/utility.h" }
+    module vec_ext              { private header "experimental/__simd/vec_ext.h" }
+
     header "experimental/simd"
     export *
   }
@@ -610,6 +622,9 @@ module std_private_bit_reference     [system] {
   header "__bit_reference"
   export *
 }
+module std_private_fwd_bit_reference [system] {
+  header "__fwd/bit_reference.h"
+}
 module std_private_config            [system] {
   textual header "__config"
   export *
@@ -786,7 +801,9 @@ module std_private_algorithm_pstl_frontend_dispatch                      [system
 module std_private_algorithm_pstl_generate                               [system] { header "__algorithm/pstl_generate.h" }
 module std_private_algorithm_pstl_is_partitioned                         [system] { header "__algorithm/pstl_is_partitioned.h" }
 module std_private_algorithm_pstl_merge                                  [system] { header "__algorithm/pstl_merge.h" }
+module std_private_algorithm_pstl_move                                   [system] { header "__algorithm/pstl_move.h" }
 module std_private_algorithm_pstl_replace                                [system] { header "__algorithm/pstl_replace.h" }
+module std_private_algorithm_pstl_rotate_copy                            [system] { header "__algorithm/pstl_rotate_copy.h" }
 module std_private_algorithm_pstl_sort                                   [system] { header "__algorithm/pstl_sort.h" }
 module std_private_algorithm_pstl_stable_sort                            [system] {
   header "__algorithm/pstl_stable_sort.h"
@@ -823,6 +840,7 @@ module std_private_algorithm_ranges_copy_n                               [system
 }
 module std_private_algorithm_ranges_count                                [system] { header "__algorithm/ranges_count.h" }
 module std_private_algorithm_ranges_count_if                             [system] { header "__algorithm/ranges_count_if.h" }
+module std_private_algorithm_ranges_ends_with                            [system] { header "__algorithm/ranges_ends_with.h" }
 module std_private_algorithm_ranges_equal                                [system] { header "__algorithm/ranges_equal.h" }
 module std_private_algorithm_ranges_equal_range                          [system] {
   header "__algorithm/ranges_equal_range.h"
@@ -1132,6 +1150,7 @@ module std_private_bit_countl         [system] { header "__bit/countl.h" }
 module std_private_bit_countr         [system] { header "__bit/countr.h" }
 module std_private_bit_endian         [system] { header "__bit/endian.h" }
 module std_private_bit_has_single_bit [system] { header "__bit/has_single_bit.h" }
+module std_private_bit_invert_if      [system] { header "__bit/invert_if.h" }
 module std_private_bit_popcount       [system] { header "__bit/popcount.h" }
 module std_private_bit_rotate         [system] { header "__bit/rotate.h" }
 
@@ -1661,7 +1680,7 @@ module std_private_ranges_all                        [system] {
   export std_private_ranges_owning_view
 }
 module std_private_ranges_as_rvalue_view             [system] { header "__ranges/as_rvalue_view.h" }
-module std_private_ranges_chunk_by_view              [system] { header "__ranages/chunk_by_view.h" }
+module std_private_ranges_chunk_by_view              [system] { header "__ranges/chunk_by_view.h" }
 module std_private_ranges_common_view                [system] { header "__ranges/common_view.h" }
 module std_private_ranges_concepts                   [system] {
   header "__ranges/concepts.h"
diff --git a/libcxx/test/libcxx/headers_in_modulemap.sh.py b/libcxx/test/libcxx/headers_in_modulemap.sh.py
new file mode 100644
index 000000000000000..ffe76280a1e5201
--- /dev/null
+++ b/libcxx/test/libcxx/headers_in_modulemap.sh.py
@@ -0,0 +1,47 @@
+# RUN: %{python} %s %{include}
+
+import pathlib
+import sys
+
+headers = list(pathlib.Path(sys.argv[1]).rglob("*"))
+modulemap = open(f"{sys.argv[1]}/module.modulemap").read()
+
+isHeaderMissing = False
+
+def ignore_header(header):
+  # exclude libc++abi files
+  if header in ["cxxabi.h", "__cxxabi_config.h"]:
+    return True
+
+  # exclude non-header files
+  if header in ["libcxx.imp", "module.modulemap"]:
+    return True
+
+  # exclude headers in __support/ - these aren't supposed to work everywhere,
+  # so they shouldn't be included in general
+  if header.startswith("__support/"):
+    return True
+
+  # exclude ext/ headers - these are non-standard extensions and are barely
+  # maintained. People should migrate away from these and we don't need to
+  # burden ourself with maintaining them in any way.
+  if header.startswith("ext/"):
+    return True
+
+  return False
+
+for header in headers:
+  if not header.is_file():
+    continue
+
+  header = header.relative_to(pathlib.Path(sys.argv[1]))
+
+  if ignore_header(str(header)):
+    continue
+
+  if not str(header) in modulemap:
+    print(f"Header {header} seems to be missing from the modulemap!")
+    isHeaderMissing = True
+
+if (isHeaderMissing):
+  exit(1)



More information about the libcxx-commits mailing list