Skip to content

Commit

Permalink
[libc++][Modules] Make top level modules for all C++ headers with OS/…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
ian-twilightcoder committed Jul 20, 2023
1 parent f12a556 commit 571178a
Show file tree
Hide file tree
Showing 26 changed files with 2,037 additions and 2,136 deletions.
2 changes: 2 additions & 0 deletions libcxx/docs/ReleaseNotes/17.rst
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ Deprecations and Removals
- The headers ``<experimental/algorithm>`` and ``<experimental/functional>`` have been removed, since all the contents
have been implemented in namespace ``std`` for at least two releases.

- The ``std`` clang module has been broken up into separate top level modules per public header.

- The formatter specialization ``template<size_t N> struct formatter<const charT[N], charT>``
has been removed. Since libc++'s format library was marked experimental there
is no backwards compatibility option. This specialization has been removed
Expand Down
1 change: 1 addition & 0 deletions libcxx/include/__stop_token/intrusive_shared_ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#ifndef _LIBCPP___STOP_TOKEN_INTRUSIVE_SHARED_PTR_H
#define _LIBCPP___STOP_TOKEN_INTRUSIVE_SHARED_PTR_H

#include <__atomic/atomic.h>
#include <__atomic/memory_order.h>
#include <__config>
#include <__type_traits/is_reference.h>
Expand Down
4 changes: 4 additions & 0 deletions libcxx/include/__thread/formatter.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

_LIBCPP_BEGIN_NAMESPACE_STD

#ifndef _LIBCPP_HAS_NO_THREADS

template <__fmt_char_type _CharT>
struct _LIBCPP_TEMPLATE_VIS formatter<__thread_id, _CharT> {
public:
Expand Down Expand Up @@ -69,6 +71,8 @@ struct _LIBCPP_TEMPLATE_VIS formatter<__thread_id, _CharT> {
__format_spec::__parser<_CharT> __parser_{.__alignment_ = __format_spec::__alignment::__right};
};

#endif // !_LIBCPP_HAS_NO_THREADS

_LIBCPP_END_NAMESPACE_STD

#endif // _LIBCPP_STD_VER >= 23
Expand Down
8 changes: 8 additions & 0 deletions libcxx/include/__threading_support
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@
#elif !defined(_LIBCPP_HAS_NO_THREADS)

#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
// Some platforms require <bits/atomic_wide_counter.h> in order for
// PTHREAD_COND_INITIALIZER to be expanded. Normally that would come
// in via <pthread.h>, but it's a non-modular header on those platforms,
// so libc++'s <math.h> usually absorbs atomic_wide_counter.h into the
// module with <math.h> and makes atomic_wide_counter.h invisible.
// Include <math.h> here to work around that.
# include <math.h>

# include <pthread.h>
# include <sched.h>
#elif defined(_LIBCPP_HAS_THREAD_API_C11)
Expand Down
1 change: 1 addition & 0 deletions libcxx/include/__utility/pair.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <__config>
#include <__fwd/array.h>
#include <__fwd/get.h>
#include <__fwd/pair.h>
#include <__fwd/subrange.h>
#include <__fwd/tuple.h>
#include <__tuple/pair_like.h>
Expand Down
Loading

0 comments on commit 571178a

Please sign in to comment.