Skip to content

Commit 571178a

Browse files
[libc++][Modules] Make top level modules for all C++ headers with OS/clang versions
The headers that include_next compiler and OS headers need to be in different top level modules in order to avoid module cycles. e.g. libc++'s stdlib.h will #include_next stdlib.h from the compiler and then the C library. Either of those are likely to include stddef.h, which will come back up to the libc++ module map and create a module cycle. Putting stdlib.h and stddef.h (and the rest of the C standard library headers) in top level modules resolves this by letting the order go cxx_stdlib_h -> os_stdlib_h -> cxx_stddef_h -> os_stddef_h. All of those headers' dependencies then need to be moved into top level modules themselves to avoid module cycles between the new top level level cstd modules. This starts to get complicated, as the libc++ C headers, by standard, have to include many of the C++ headers, which include the private detail headers, which are intertwined. e.g. some `__algorithm` headers include `__memory` headers and vice versa. Make top level modules for all of the libc++ headers to easily guarantee that the modules aren't cyclic. Add enough module exports to fix `check-cxx` and `run-buildbot generic-modules`. `__stop_token/intrusive_shared_ptr.h` uses `__atomic/atomic.h` but has no include path to it. Add that include. `math.h` absorbs `bits/atomic_wide_counter.h` on some platforms that don't have modules, work around that by including `math.h` in `__threading_support`. <mutex> doesn't actually require threads, there are a few pieces like once_flag that work without threads. Remove the requirement from its module. AIX is no longer able to support modular builds. Reviewed By: ldionne, #libc Differential Revision: https://reviews.llvm.org/D144322
1 parent f12a556 commit 571178a

26 files changed

+2037
-2136
lines changed

libcxx/docs/ReleaseNotes/17.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ Deprecations and Removals
148148
- The headers ``<experimental/algorithm>`` and ``<experimental/functional>`` have been removed, since all the contents
149149
have been implemented in namespace ``std`` for at least two releases.
150150

151+
- The ``std`` clang module has been broken up into separate top level modules per public header.
152+
151153
- The formatter specialization ``template<size_t N> struct formatter<const charT[N], charT>``
152154
has been removed. Since libc++'s format library was marked experimental there
153155
is no backwards compatibility option. This specialization has been removed

libcxx/include/__stop_token/intrusive_shared_ptr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#ifndef _LIBCPP___STOP_TOKEN_INTRUSIVE_SHARED_PTR_H
1111
#define _LIBCPP___STOP_TOKEN_INTRUSIVE_SHARED_PTR_H
1212

13+
#include <__atomic/atomic.h>
1314
#include <__atomic/memory_order.h>
1415
#include <__config>
1516
#include <__type_traits/is_reference.h>

libcxx/include/__thread/formatter.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131

3232
_LIBCPP_BEGIN_NAMESPACE_STD
3333

34+
#ifndef _LIBCPP_HAS_NO_THREADS
35+
3436
template <__fmt_char_type _CharT>
3537
struct _LIBCPP_TEMPLATE_VIS formatter<__thread_id, _CharT> {
3638
public:
@@ -69,6 +71,8 @@ struct _LIBCPP_TEMPLATE_VIS formatter<__thread_id, _CharT> {
6971
__format_spec::__parser<_CharT> __parser_{.__alignment_ = __format_spec::__alignment::__right};
7072
};
7173

74+
#endif // !_LIBCPP_HAS_NO_THREADS
75+
7276
_LIBCPP_END_NAMESPACE_STD
7377

7478
#endif // _LIBCPP_STD_VER >= 23

libcxx/include/__threading_support

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@
3030
#elif !defined(_LIBCPP_HAS_NO_THREADS)
3131

3232
#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
33+
// Some platforms require <bits/atomic_wide_counter.h> in order for
34+
// PTHREAD_COND_INITIALIZER to be expanded. Normally that would come
35+
// in via <pthread.h>, but it's a non-modular header on those platforms,
36+
// so libc++'s <math.h> usually absorbs atomic_wide_counter.h into the
37+
// module with <math.h> and makes atomic_wide_counter.h invisible.
38+
// Include <math.h> here to work around that.
39+
# include <math.h>
40+
3341
# include <pthread.h>
3442
# include <sched.h>
3543
#elif defined(_LIBCPP_HAS_THREAD_API_C11)

libcxx/include/__utility/pair.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <__config>
1616
#include <__fwd/array.h>
1717
#include <__fwd/get.h>
18+
#include <__fwd/pair.h>
1819
#include <__fwd/subrange.h>
1920
#include <__fwd/tuple.h>
2021
#include <__tuple/pair_like.h>

0 commit comments

Comments
 (0)