[libcxx-commits] [libcxx] 4d4c70c - [libc++][modules] Removes the module partitions.

Mark de Wever via libcxx-commits libcxx-commits at lists.llvm.org
Wed Aug 9 10:39:13 PDT 2023


Author: Mark de Wever
Date: 2023-08-09T19:39:08+02:00
New Revision: 4d4c70c91c5511f8c051623bcc1a76064d5bf687

URL: https://github.com/llvm/llvm-project/commit/4d4c70c91c5511f8c051623bcc1a76064d5bf687
DIFF: https://github.com/llvm/llvm-project/commit/4d4c70c91c5511f8c051623bcc1a76064d5bf687.diff

LOG: [libc++][modules] Removes the module partitions.

This patch is based on the suggestion by @ChuanqiXu on discourse
(https://discourse.llvm.org/t/alternatives-to-the-implementation-of-std-modules/71958)

Instead of making a module partition per header every header gets an inc
file which contains the exports per header. The std module then includes
all public headers and these inc files. The one file per header is
useful for testing purposes. The CI tests whether the exports of a
header's module partition matches the "public" named declarations in the
header. With one file per header this can still be done.

The patch improves compilation time of files using "import std;" and the
size of the std module.

A comparision of the compilation speed using a libc++ test
  build/bin/llvm-lit -a -Dstd=c++23 -Denable_modules=std libcxx/test/std/modules/std.pass.cpp

Which boils down to
  import std;

  int main(int, char**) {
    std::println("Hello modular world");
    return 0;
  }
and has -ftime-report enabled

Before
===-------------------------------------------------------------------------===
                          Clang front-end time report
===-------------------------------------------------------------------------===
  Total Execution Time: 8.6585 seconds (8.6619 wall clock)

   ---User Time---   --System Time--   --User+System--   ---Wall Time---  --- Name ---
   4.5041 ( 57.2%)   0.4264 ( 54.4%)   4.9305 ( 56.9%)   4.9331 ( 57.0%)  Clang front-end timer
   3.2037 ( 40.7%)   0.2408 ( 30.7%)   3.4445 ( 39.8%)   3.4452 ( 39.8%)  Reading modules
   0.1665 (  2.1%)   0.1170 ( 14.9%)   0.2835 (  3.3%)   0.2837 (  3.3%)  Loading .../build/test/__config_module__/CMakeFiles/std.dir/std.pcm
   7.8744 (100.0%)   0.7842 (100.0%)   8.6585 (100.0%)   8.6619 (100.0%)  Total

After
===-------------------------------------------------------------------------===
                          Clang front-end time report
===-------------------------------------------------------------------------===
  Total Execution Time: 1.2420 seconds (1.2423 wall clock)

   ---User Time---   --System Time--   --User+System--   ---Wall Time---  --- Name ---
   0.8892 ( 84.6%)   0.1698 ( 88.8%)   1.0590 ( 85.3%)   1.0590 ( 85.2%)  Clang front-end timer
   0.1533 ( 14.6%)   0.0168 (  8.8%)   0.1701 ( 13.7%)   0.1704 ( 13.7%)  Reading modules
   0.0082 (  0.8%)   0.0047 (  2.5%)   0.0129 (  1.0%)   0.0129 (  1.0%)  Loading .../build/test/__config_module__/CMakeFiles/std.dir/std.pcm
   1.0507 (100.0%)   0.1913 (100.0%)   1.2420 (100.0%)   1.2423 (100.0%)  Total

Using "include <print>" instead of "import module;"
===-------------------------------------------------------------------------===
                          Clang front-end time report
===-------------------------------------------------------------------------===
  Total Execution Time: 2.1507 seconds (2.1517 wall clock)

   ---User Time---   --System Time--   --User+System--   ---Wall Time---  --- Name ---
   1.9714 (100.0%)   0.1793 (100.0%)   2.1507 (100.0%)   2.1517 (100.0%)  Clang front-end timer
   1.9714 (100.0%)   0.1793 (100.0%)   2.1507 (100.0%)   2.1517 (100.0%)  Total

It's possible to use the std module in external projects
(https://libcxx.llvm.org/Modules.html#using-in-external-projects)

Tested this with a private project to validate the size of the generated files:

Before
$ du -sch std-*
448M	std-build
508K	std-src
120K	std-subbuild
449M	total

After
$ du -sch std-*
29M	std-build
1004K	std-src
132K	std-subbuild
30M	total

Reviewed By: ldionne, #libc

Differential Revision: https://reviews.llvm.org/D156907

Added: 
    libcxx/modules/README.md
    libcxx/modules/std.cppm.in
    libcxx/modules/std/algorithm.inc
    libcxx/modules/std/any.inc
    libcxx/modules/std/array.inc
    libcxx/modules/std/atomic.inc
    libcxx/modules/std/barrier.inc
    libcxx/modules/std/bit.inc
    libcxx/modules/std/bitset.inc
    libcxx/modules/std/cassert.inc
    libcxx/modules/std/cctype.inc
    libcxx/modules/std/cerrno.inc
    libcxx/modules/std/cfenv.inc
    libcxx/modules/std/cfloat.inc
    libcxx/modules/std/charconv.inc
    libcxx/modules/std/chrono.inc
    libcxx/modules/std/cinttypes.inc
    libcxx/modules/std/climits.inc
    libcxx/modules/std/clocale.inc
    libcxx/modules/std/cmath.inc
    libcxx/modules/std/codecvt.inc
    libcxx/modules/std/compare.inc
    libcxx/modules/std/complex.inc
    libcxx/modules/std/concepts.inc
    libcxx/modules/std/condition_variable.inc
    libcxx/modules/std/coroutine.inc
    libcxx/modules/std/csetjmp.inc
    libcxx/modules/std/csignal.inc
    libcxx/modules/std/cstdarg.inc
    libcxx/modules/std/cstddef.inc
    libcxx/modules/std/cstdint.inc
    libcxx/modules/std/cstdio.inc
    libcxx/modules/std/cstdlib.inc
    libcxx/modules/std/cstring.inc
    libcxx/modules/std/ctime.inc
    libcxx/modules/std/cuchar.inc
    libcxx/modules/std/cwchar.inc
    libcxx/modules/std/cwctype.inc
    libcxx/modules/std/deque.inc
    libcxx/modules/std/exception.inc
    libcxx/modules/std/execution.inc
    libcxx/modules/std/expected.inc
    libcxx/modules/std/filesystem.inc
    libcxx/modules/std/flat_map.inc
    libcxx/modules/std/flat_set.inc
    libcxx/modules/std/format.inc
    libcxx/modules/std/forward_list.inc
    libcxx/modules/std/fstream.inc
    libcxx/modules/std/functional.inc
    libcxx/modules/std/future.inc
    libcxx/modules/std/generator.inc
    libcxx/modules/std/hazard_pointer.inc
    libcxx/modules/std/initializer_list.inc
    libcxx/modules/std/iomanip.inc
    libcxx/modules/std/ios.inc
    libcxx/modules/std/iosfwd.inc
    libcxx/modules/std/iostream.inc
    libcxx/modules/std/istream.inc
    libcxx/modules/std/iterator.inc
    libcxx/modules/std/latch.inc
    libcxx/modules/std/limits.inc
    libcxx/modules/std/list.inc
    libcxx/modules/std/locale.inc
    libcxx/modules/std/map.inc
    libcxx/modules/std/mdspan.inc
    libcxx/modules/std/memory.inc
    libcxx/modules/std/memory_resource.inc
    libcxx/modules/std/mutex.inc
    libcxx/modules/std/new.inc
    libcxx/modules/std/numbers.inc
    libcxx/modules/std/numeric.inc
    libcxx/modules/std/optional.inc
    libcxx/modules/std/ostream.inc
    libcxx/modules/std/print.inc
    libcxx/modules/std/queue.inc
    libcxx/modules/std/random.inc
    libcxx/modules/std/ranges.inc
    libcxx/modules/std/ratio.inc
    libcxx/modules/std/rcu.inc
    libcxx/modules/std/regex.inc
    libcxx/modules/std/scoped_allocator.inc
    libcxx/modules/std/semaphore.inc
    libcxx/modules/std/set.inc
    libcxx/modules/std/shared_mutex.inc
    libcxx/modules/std/source_location.inc
    libcxx/modules/std/span.inc
    libcxx/modules/std/spanstream.inc
    libcxx/modules/std/sstream.inc
    libcxx/modules/std/stack.inc
    libcxx/modules/std/stacktrace.inc
    libcxx/modules/std/stdexcept.inc
    libcxx/modules/std/stdfloat.inc
    libcxx/modules/std/stop_token.inc
    libcxx/modules/std/streambuf.inc
    libcxx/modules/std/string.inc
    libcxx/modules/std/string_view.inc
    libcxx/modules/std/strstream.inc
    libcxx/modules/std/syncstream.inc
    libcxx/modules/std/system_error.inc
    libcxx/modules/std/text_encoding.inc
    libcxx/modules/std/thread.inc
    libcxx/modules/std/tuple.inc
    libcxx/modules/std/type_traits.inc
    libcxx/modules/std/typeindex.inc
    libcxx/modules/std/typeinfo.inc
    libcxx/modules/std/unordered_map.inc
    libcxx/modules/std/unordered_set.inc
    libcxx/modules/std/utility.inc
    libcxx/modules/std/valarray.inc
    libcxx/modules/std/variant.inc
    libcxx/modules/std/vector.inc
    libcxx/modules/std/version.inc

Modified: 
    libcxx/modules/CMakeLists.txt
    libcxx/modules/CMakeLists.txt.in
    libcxx/test/libcxx/module_std.gen.py
    libcxx/test/tools/clang_tidy_checks/header_exportable_declarations.cpp

Removed: 
    libcxx/modules/std.cppm
    libcxx/modules/std/algorithm.cppm
    libcxx/modules/std/any.cppm
    libcxx/modules/std/array.cppm
    libcxx/modules/std/atomic.cppm
    libcxx/modules/std/barrier.cppm
    libcxx/modules/std/bit.cppm
    libcxx/modules/std/bitset.cppm
    libcxx/modules/std/cassert.cppm
    libcxx/modules/std/cctype.cppm
    libcxx/modules/std/cerrno.cppm
    libcxx/modules/std/cfenv.cppm
    libcxx/modules/std/cfloat.cppm
    libcxx/modules/std/charconv.cppm
    libcxx/modules/std/chrono.cppm
    libcxx/modules/std/cinttypes.cppm
    libcxx/modules/std/climits.cppm
    libcxx/modules/std/clocale.cppm
    libcxx/modules/std/cmath.cppm
    libcxx/modules/std/codecvt.cppm
    libcxx/modules/std/compare.cppm
    libcxx/modules/std/complex.cppm
    libcxx/modules/std/concepts.cppm
    libcxx/modules/std/condition_variable.cppm
    libcxx/modules/std/coroutine.cppm
    libcxx/modules/std/csetjmp.cppm
    libcxx/modules/std/csignal.cppm
    libcxx/modules/std/cstdarg.cppm
    libcxx/modules/std/cstddef.cppm
    libcxx/modules/std/cstdint.cppm
    libcxx/modules/std/cstdio.cppm
    libcxx/modules/std/cstdlib.cppm
    libcxx/modules/std/cstring.cppm
    libcxx/modules/std/ctime.cppm
    libcxx/modules/std/cuchar.cppm
    libcxx/modules/std/cwchar.cppm
    libcxx/modules/std/cwctype.cppm
    libcxx/modules/std/deque.cppm
    libcxx/modules/std/exception.cppm
    libcxx/modules/std/execution.cppm
    libcxx/modules/std/expected.cppm
    libcxx/modules/std/filesystem.cppm
    libcxx/modules/std/flat_map.cppm
    libcxx/modules/std/flat_set.cppm
    libcxx/modules/std/format.cppm
    libcxx/modules/std/forward_list.cppm
    libcxx/modules/std/fstream.cppm
    libcxx/modules/std/functional.cppm
    libcxx/modules/std/future.cppm
    libcxx/modules/std/generator.cppm
    libcxx/modules/std/hazard_pointer.cppm
    libcxx/modules/std/initializer_list.cppm
    libcxx/modules/std/iomanip.cppm
    libcxx/modules/std/ios.cppm
    libcxx/modules/std/iosfwd.cppm
    libcxx/modules/std/iostream.cppm
    libcxx/modules/std/istream.cppm
    libcxx/modules/std/iterator.cppm
    libcxx/modules/std/latch.cppm
    libcxx/modules/std/limits.cppm
    libcxx/modules/std/list.cppm
    libcxx/modules/std/locale.cppm
    libcxx/modules/std/map.cppm
    libcxx/modules/std/mdspan.cppm
    libcxx/modules/std/memory.cppm
    libcxx/modules/std/memory_resource.cppm
    libcxx/modules/std/mutex.cppm
    libcxx/modules/std/new.cppm
    libcxx/modules/std/numbers.cppm
    libcxx/modules/std/numeric.cppm
    libcxx/modules/std/optional.cppm
    libcxx/modules/std/ostream.cppm
    libcxx/modules/std/print.cppm
    libcxx/modules/std/queue.cppm
    libcxx/modules/std/random.cppm
    libcxx/modules/std/ranges.cppm
    libcxx/modules/std/ratio.cppm
    libcxx/modules/std/rcu.cppm
    libcxx/modules/std/regex.cppm
    libcxx/modules/std/scoped_allocator.cppm
    libcxx/modules/std/semaphore.cppm
    libcxx/modules/std/set.cppm
    libcxx/modules/std/shared_mutex.cppm
    libcxx/modules/std/source_location.cppm
    libcxx/modules/std/span.cppm
    libcxx/modules/std/spanstream.cppm
    libcxx/modules/std/sstream.cppm
    libcxx/modules/std/stack.cppm
    libcxx/modules/std/stacktrace.cppm
    libcxx/modules/std/stdexcept.cppm
    libcxx/modules/std/stdfloat.cppm
    libcxx/modules/std/stop_token.cppm
    libcxx/modules/std/streambuf.cppm
    libcxx/modules/std/string.cppm
    libcxx/modules/std/string_view.cppm
    libcxx/modules/std/strstream.cppm
    libcxx/modules/std/syncstream.cppm
    libcxx/modules/std/system_error.cppm
    libcxx/modules/std/text_encoding.cppm
    libcxx/modules/std/thread.cppm
    libcxx/modules/std/tuple.cppm
    libcxx/modules/std/type_traits.cppm
    libcxx/modules/std/typeindex.cppm
    libcxx/modules/std/typeinfo.cppm
    libcxx/modules/std/unordered_map.cppm
    libcxx/modules/std/unordered_set.cppm
    libcxx/modules/std/utility.cppm
    libcxx/modules/std/valarray.cppm
    libcxx/modules/std/variant.cppm
    libcxx/modules/std/vector.cppm
    libcxx/modules/std/version.cppm


################################################################################
diff  --git a/libcxx/modules/CMakeLists.txt b/libcxx/modules/CMakeLists.txt
index d24ddb0efc7fa0..572ee2d3fe2bdd 100644
--- a/libcxx/modules/CMakeLists.txt
+++ b/libcxx/modules/CMakeLists.txt
@@ -5,120 +5,117 @@ endif()
 
 # The headers of Table 24: C++ library headers [tab:headers.cpp]
 # and the headers of Table 25: C++ headers for C library facilities [tab:headers.cpp.c]
-set(LIBCXX_SOURCES_MODULE_STD
-  std.cppm
-  std/algorithm.cppm
-  std/any.cppm
-  std/array.cppm
-  std/atomic.cppm
-  std/barrier.cppm
-  std/bit.cppm
-  std/bitset.cppm
-  std/cassert.cppm
-  std/cctype.cppm
-  std/cerrno.cppm
-  std/cfenv.cppm
-  std/cfloat.cppm
-  std/charconv.cppm
-  std/chrono.cppm
-  std/cinttypes.cppm
-  std/climits.cppm
-  std/clocale.cppm
-  std/cmath.cppm
-  std/codecvt.cppm
-  std/compare.cppm
-  std/complex.cppm
-  std/concepts.cppm
-  std/condition_variable.cppm
-  std/coroutine.cppm
-  std/csetjmp.cppm
-  std/csignal.cppm
-  std/cstdarg.cppm
-  std/cstddef.cppm
-  std/cstdint.cppm
-  std/cstdio.cppm
-  std/cstdlib.cppm
-  std/cstring.cppm
-  std/ctime.cppm
-  std/cuchar.cppm
-  std/cwchar.cppm
-  std/cwctype.cppm
-  std/deque.cppm
-  std/exception.cppm
-  std/execution.cppm
-  std/expected.cppm
-  std/filesystem.cppm
-  std/flat_map.cppm
-  std/flat_set.cppm
-  std/format.cppm
-  std/forward_list.cppm
-  std/fstream.cppm
-  std/functional.cppm
-  std/future.cppm
-  std/generator.cppm
-  std/hazard_pointer.cppm
-  std/initializer_list.cppm
-  std/iomanip.cppm
-  std/ios.cppm
-  std/iosfwd.cppm
-  std/iostream.cppm
-  std/iostream.cppm
-  std/istream.cppm
-  std/iterator.cppm
-  std/latch.cppm
-  std/limits.cppm
-  std/list.cppm
-  std/locale.cppm
-  std/map.cppm
-  std/mdspan.cppm
-  std/memory.cppm
-  std/memory_resource.cppm
-  std/mutex.cppm
-  std/new.cppm
-  std/numbers.cppm
-  std/numeric.cppm
-  std/optional.cppm
-  std/ostream.cppm
-  std/print.cppm
-  std/queue.cppm
-  std/random.cppm
-  std/ranges.cppm
-  std/ratio.cppm
-  std/rcu.cppm
-  std/regex.cppm
-  std/scoped_allocator.cppm
-  std/semaphore.cppm
-  std/set.cppm
-  std/shared_mutex.cppm
-  std/source_location.cppm
-  std/span.cppm
-  std/spanstream.cppm
-  std/sstream.cppm
-  std/stack.cppm
-  std/stacktrace.cppm
-  std/stdexcept.cppm
-  std/stdexcept.cppm
-  std/stdfloat.cppm
-  std/stop_token.cppm
-  std/streambuf.cppm
-  std/string.cppm
-  std/string_view.cppm
-  std/strstream.cppm
-  std/syncstream.cppm
-  std/system_error.cppm
-  std/text_encoding.cppm
-  std/thread.cppm
-  std/tuple.cppm
-  std/type_traits.cppm
-  std/typeindex.cppm
-  std/typeinfo.cppm
-  std/unordered_map.cppm
-  std/unordered_set.cppm
-  std/utility.cppm
-  std/valarray.cppm
-  std/variant.cppm
-  std/vector.cppm
-  std/version.cppm
+set(LIBCXX_MODULE_STD_SOURCES
+  std/algorithm.inc
+  std/any.inc
+  std/array.inc
+  std/atomic.inc
+  std/barrier.inc
+  std/bit.inc
+  std/bitset.inc
+  std/cassert.inc
+  std/cctype.inc
+  std/cerrno.inc
+  std/cfenv.inc
+  std/cfloat.inc
+  std/charconv.inc
+  std/chrono.inc
+  std/cinttypes.inc
+  std/climits.inc
+  std/clocale.inc
+  std/cmath.inc
+  std/codecvt.inc
+  std/compare.inc
+  std/complex.inc
+  std/concepts.inc
+  std/condition_variable.inc
+  std/coroutine.inc
+  std/csetjmp.inc
+  std/csignal.inc
+  std/cstdarg.inc
+  std/cstddef.inc
+  std/cstdint.inc
+  std/cstdio.inc
+  std/cstdlib.inc
+  std/cstring.inc
+  std/ctime.inc
+  std/cuchar.inc
+  std/cwchar.inc
+  std/cwctype.inc
+  std/deque.inc
+  std/exception.inc
+  std/execution.inc
+  std/expected.inc
+  std/filesystem.inc
+  std/flat_map.inc
+  std/flat_set.inc
+  std/format.inc
+  std/forward_list.inc
+  std/fstream.inc
+  std/functional.inc
+  std/future.inc
+  std/generator.inc
+  std/hazard_pointer.inc
+  std/initializer_list.inc
+  std/iomanip.inc
+  std/ios.inc
+  std/iosfwd.inc
+  std/iostream.inc
+  std/istream.inc
+  std/iterator.inc
+  std/latch.inc
+  std/limits.inc
+  std/list.inc
+  std/locale.inc
+  std/map.inc
+  std/mdspan.inc
+  std/memory.inc
+  std/memory_resource.inc
+  std/mutex.inc
+  std/new.inc
+  std/numbers.inc
+  std/numeric.inc
+  std/optional.inc
+  std/ostream.inc
+  std/print.inc
+  std/queue.inc
+  std/random.inc
+  std/ranges.inc
+  std/ratio.inc
+  std/rcu.inc
+  std/regex.inc
+  std/scoped_allocator.inc
+  std/semaphore.inc
+  std/set.inc
+  std/shared_mutex.inc
+  std/source_location.inc
+  std/span.inc
+  std/spanstream.inc
+  std/sstream.inc
+  std/stack.inc
+  std/stacktrace.inc
+  std/stdexcept.inc
+  std/stdfloat.inc
+  std/stop_token.inc
+  std/streambuf.inc
+  std/string.inc
+  std/string_view.inc
+  std/strstream.inc
+  std/syncstream.inc
+  std/system_error.inc
+  std/text_encoding.inc
+  std/thread.inc
+  std/tuple.inc
+  std/type_traits.inc
+  std/typeindex.inc
+  std/typeinfo.inc
+  std/unordered_map.inc
+  std/unordered_set.inc
+  std/utility.inc
+  std/valarray.inc
+  std/variant.inc
+  std/vector.inc
+  std/version.inc
 )
 
 # TODO MODULES the CMakeLists.txt in the install directory is only temporary
@@ -132,8 +129,24 @@ configure_file(
   @ONLY
 )
 
-set(_all_modules "${LIBCXX_GENERATED_MODULE_DIR}/CMakeLists.txt")
-foreach(file ${LIBCXX_SOURCES_MODULE_STD})
+set(LIBCXX_MODULE_STD_INCLUDE_SOURCES)
+foreach(file ${LIBCXX_MODULE_STD_SOURCES})
+  set(
+    LIBCXX_MODULE_STD_INCLUDE_SOURCES
+    "${LIBCXX_MODULE_STD_INCLUDE_SOURCES}#include \"${file}\"\n"
+  )
+endforeach()
+
+configure_file(
+  "std.cppm.in"
+  "${LIBCXX_GENERATED_MODULE_DIR}/std.cppm"
+  @ONLY
+)
+
+set(_all_modules)
+list(APPEND _all_modules "${LIBCXX_GENERATED_MODULE_DIR}/CMakeLists.txt")
+list(APPEND _all_modules "${LIBCXX_GENERATED_MODULE_DIR}/std.cppm")
+foreach(file ${LIBCXX_MODULE_STD_SOURCES})
   set(src "${CMAKE_CURRENT_SOURCE_DIR}/${file}")
   set(dst "${LIBCXX_GENERATED_MODULE_DIR}/${file}")
   add_custom_command(OUTPUT ${dst}

diff  --git a/libcxx/modules/CMakeLists.txt.in b/libcxx/modules/CMakeLists.txt.in
index 3cf20aebfa2579..88272e170ed352 100644
--- a/libcxx/modules/CMakeLists.txt.in
+++ b/libcxx/modules/CMakeLists.txt.in
@@ -48,7 +48,7 @@ endif()
 add_library(std)
 target_sources(std
   PUBLIC FILE_SET cxx_modules TYPE CXX_MODULES FILES
-    @LIBCXX_SOURCES_MODULE_STD@
+    std.cppm
 )
 
 target_compile_definitions(std PRIVATE _LIBCPP_ENABLE_EXPERIMENTAL)

diff  --git a/libcxx/modules/README.md b/libcxx/modules/README.md
new file mode 100644
index 00000000000000..23dd60602beb18
--- /dev/null
+++ b/libcxx/modules/README.md
@@ -0,0 +1,21 @@
+# The "module partitions" for the std module
+
+The files in this directory contain the exported named declarations per header.
+These files are used for the following purposes:
+
+ - During testing exported named declarations are tested against the named
+   declarations in the associated header. This excludes reserved names; they
+   are not exported.
+ - Generate the module std.
+
+These use cases require including the required headers for these "partitions"
+at 
diff erent locations. This means the user of these "partitions" are
+responsible for including the proper header and validating whether the header can
+be loaded in the current libc++ configuration. For example "include <locale>"
+fails when locales are not available. The "partitions" use the libc++ feature
+macros to export the declarations available in the current configuration. This
+configuration is available if the user includes the `__config' header.
+
+We use `.inc` files that we include from the top-level module instead of
+using real C++ module partitions. This is a lot faster than module partitions,
+see [this](https://discourse.llvm.org/t/alternatives-to-the-implementation-of-std-modules/71958) for details.

diff  --git a/libcxx/modules/std.cppm b/libcxx/modules/std.cppm
deleted file mode 100644
index fcd7d55bbed0ae..00000000000000
--- a/libcxx/modules/std.cppm
+++ /dev/null
@@ -1,123 +0,0 @@
-// -*- C++ -*-
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-export module std;
-
-// The headers of Table 24: C++ library headers [tab:headers.cpp]
-// and the headers of Table 25: C++ headers for C library facilities [tab:headers.cpp.c]
-export import :__new; // Note new is a keyword and not a valid identifier
-export import :algorithm;
-export import :any;
-export import :array;
-export import :atomic;
-export import :barrier;
-export import :bit;
-export import :bitset;
-export import :cassert;
-export import :cctype;
-export import :cerrno;
-export import :cfenv;
-export import :cfloat;
-export import :charconv;
-export import :chrono;
-export import :cinttypes;
-export import :climits;
-export import :clocale;
-export import :cmath;
-export import :codecvt;
-export import :compare;
-export import :complex;
-export import :concepts;
-export import :condition_variable;
-export import :coroutine;
-export import :csetjmp;
-export import :csignal;
-export import :cstdarg;
-export import :cstddef;
-export import :cstdio;
-export import :cstdlib;
-export import :cstdint;
-export import :cstring;
-export import :ctime;
-export import :cuchar;
-export import :cwchar;
-export import :cwctype;
-export import :deque;
-export import :exception;
-export import :execution;
-export import :expected;
-export import :filesystem;
-export import :flat_map;
-export import :flat_set;
-export import :format;
-export import :forward_list;
-export import :fstream;
-export import :functional;
-export import :future;
-export import :generator;
-export import :hazard_pointer;
-export import :initializer_list;
-export import :iomanip;
-export import :ios;
-export import :iosfwd;
-export import :iostream;
-export import :istream;
-export import :iterator;
-export import :latch;
-export import :limits;
-export import :list;
-export import :locale;
-export import :map;
-export import :mdspan;
-export import :memory;
-export import :memory_resource;
-export import :mutex;
-export import :numbers;
-export import :numeric;
-export import :optional;
-export import :ostream;
-export import :print;
-export import :queue;
-export import :random;
-export import :ranges;
-export import :ratio;
-export import :rcu;
-export import :regex;
-export import :scoped_allocator;
-export import :semaphore;
-export import :set;
-export import :shared_mutex;
-export import :source_location;
-export import :span;
-export import :spanstream;
-export import :sstream;
-export import :stack;
-export import :stacktrace;
-export import :stdexcept;
-export import :stdfloat;
-export import :stop_token;
-export import :streambuf;
-export import :string;
-export import :string_view;
-export import :strstream;
-export import :syncstream;
-export import :system_error;
-export import :text_encoding;
-export import :thread;
-export import :tuple;
-export import :type_traits;
-export import :typeindex;
-export import :typeinfo;
-export import :unordered_map;
-export import :unordered_set;
-export import :utility;
-export import :valarray;
-export import :variant;
-export import :vector;
-export import :version;

diff  --git a/libcxx/modules/std.cppm.in b/libcxx/modules/std.cppm.in
new file mode 100644
index 00000000000000..dd611d5dbca386
--- /dev/null
+++ b/libcxx/modules/std.cppm.in
@@ -0,0 +1,170 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+module;
+
+#include <__config>
+
+// TODO MODULES This could be generated
+
+// The headers of Table 24: C++ library headers [tab:headers.cpp]
+// and the headers of Table 25: C++ headers for C library facilities [tab:headers.cpp.c]
+#include <algorithm>
+#include <any>
+#include <array>
+#include <atomic>
+#include <barrier>
+#include <bit>
+#include <bitset>
+#include <cassert>
+#include <cctype>
+#include <cerrno>
+#include <cfenv>
+#include <cfloat>
+#include <charconv>
+#include <chrono>
+#include <cinttypes>
+#include <climits>
+#include <cmath>
+#include <compare>
+#include <complex>
+#include <concepts>
+#include <condition_variable>
+#include <coroutine>
+#include <csetjmp>
+#include <csignal>
+#include <cstdarg>
+#include <cstddef>
+#include <cstdint>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+#include <ctime>
+#include <cuchar>
+#include <deque>
+#include <exception>
+#include <execution>
+#include <expected>
+#include <filesystem>
+#include <format>
+#include <forward_list>
+#include <functional>
+#include <future>
+#include <initializer_list>
+#include <iosfwd>
+#include <iterator>
+#include <latch>
+#include <limits>
+#include <list>
+#include <map>
+#include <mdspan>
+#include <memory>
+#include <memory_resource>
+#include <mutex>
+#include <new>
+#include <numbers>
+#include <numeric>
+#include <optional>
+#include <print>
+#include <queue>
+#include <random>
+#include <ranges>
+#include <ratio>
+#include <scoped_allocator>
+#include <semaphore>
+#include <set>
+#include <shared_mutex>
+#include <source_location>
+#include <span>
+#include <stack>
+#include <stdexcept>
+#include <stop_token>
+#include <string>
+#include <string_view>
+#include <system_error>
+#include <thread>
+#include <tuple>
+#include <type_traits>
+#include <typeindex>
+#include <typeinfo>
+#include <unordered_map>
+#include <unordered_set>
+#include <utility>
+#include <valarray>
+#include <variant>
+#include <vector>
+#include <version>
+
+// *** Headers disabled by a feature ***
+
+#ifndef _LIBCPP_HAS_NO_LOCALIZATION
+#  include <clocale>
+#  include <codecvt>
+#  include <fstream>
+#  include <iomanip>
+#  include <ios>
+#  include <iostream>
+#  include <istream>
+#  include <locale>
+#  include <ostream>
+#  include <regex>
+#  include <sstream>
+#  include <streambuf>
+#  include <strstream>
+#endif // _LIBCPP_HAS_NO_LOCALIZATION
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+#  include <cwchar>
+#  include <cwctype>
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
+
+// *** Headers not yet available ***
+#if __has_include(<generator>)
+#  error "include <generator> unconditionally"
+#  include <generator>
+#endif //   __has_include(<generator>)
+#if __has_include(<hazard_pointer>)
+#  error "include <hazard_pointer> unconditionally"
+#  include <hazard_pointer>
+#endif //   __has_include(<hazard_pointer>)
+#if __has_include(<flat_map>)
+#  error "include <flat_map> unconditionally"
+#  include <flat_map>
+#endif // __has_include(<flat_map>)
+#if __has_include(<flat_set>)
+#  error "include <flat_set> unconditionally"
+#  include <flat_set>
+#endif //  __has_include(<flat_set>)
+#if __has_include(<rcu>)
+#  error "include <rcu> unconditionally"
+#  include <rcu>
+#endif //   __has_include(<rcu>)
+#if __has_include(<spanstream>)
+#  error "include <spanstream> unconditionally"
+#  include <spanstream>
+#endif //   __has_include(<spanstream>)
+#if __has_include(<stacktrace>)
+#  error "include <stacktrace> unconditionally"
+#  include <stacktrace>
+#endif //   __has_include(<stacktrace>)
+#if __has_include(<stdfloat>)
+#  error "include <stdfloat> unconditionally"
+#  include <stdfloat>
+#endif //   __has_include(<stdfloat>)
+#if __has_include(<syncstream>)
+#  error "include <syncstream> unconditionally"
+#  include <syncstream>
+#endif //   __has_include(<syncstream>)
+#if __has_include(<text_encoding>)
+#  error "include <text_encoding> unconditionally"
+#  include <text_encoding>
+#endif //   __has_include(<text_encoding>)
+
+export module std;
+
+ at LIBCXX_MODULE_STD_INCLUDE_SOURCES@

diff  --git a/libcxx/modules/std/algorithm.cppm b/libcxx/modules/std/algorithm.inc
similarity index 99%
rename from libcxx/modules/std/algorithm.cppm
rename to libcxx/modules/std/algorithm.inc
index 6598c192f55ce8..bb38f39df88896 100644
--- a/libcxx/modules/std/algorithm.cppm
+++ b/libcxx/modules/std/algorithm.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <algorithm>
-
-export module std:algorithm;
 export namespace std {
   namespace ranges {
     // [algorithms.results], algorithm result types

diff  --git a/libcxx/modules/std/any.cppm b/libcxx/modules/std/any.inc
similarity index 93%
rename from libcxx/modules/std/any.cppm
rename to libcxx/modules/std/any.inc
index f44f4da4ed646a..c57257ede84909 100644
--- a/libcxx/modules/std/any.cppm
+++ b/libcxx/modules/std/any.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <any>
-
-export module std:any;
 export namespace std {
 
   // [any.bad.any.cast], class bad_any_cast

diff  --git a/libcxx/modules/std/array.cppm b/libcxx/modules/std/array.inc
similarity index 93%
rename from libcxx/modules/std/array.cppm
rename to libcxx/modules/std/array.inc
index d7d067230686a3..d55779c8bd128b 100644
--- a/libcxx/modules/std/array.cppm
+++ b/libcxx/modules/std/array.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <array>
-
-export module std:array;
 export namespace std {
 
   // [array], class template array

diff  --git a/libcxx/modules/std/atomic.cppm b/libcxx/modules/std/atomic.inc
similarity index 98%
rename from libcxx/modules/std/atomic.cppm
rename to libcxx/modules/std/atomic.inc
index faf902b768d750..5139b7531093d7 100644
--- a/libcxx/modules/std/atomic.cppm
+++ b/libcxx/modules/std/atomic.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <atomic>
-
-export module std:atomic;
 export namespace std {
 
   // [atomics.order], order and consistency

diff  --git a/libcxx/modules/std/barrier.cppm b/libcxx/modules/std/barrier.inc
similarity index 89%
rename from libcxx/modules/std/barrier.cppm
rename to libcxx/modules/std/barrier.inc
index bdecfaedad8213..bafd87e4acb2f1 100644
--- a/libcxx/modules/std/barrier.cppm
+++ b/libcxx/modules/std/barrier.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <barrier>
-
-export module std:barrier;
 export namespace std {
   using std::barrier;
 } // namespace std

diff  --git a/libcxx/modules/std/bit.cppm b/libcxx/modules/std/bit.inc
similarity index 95%
rename from libcxx/modules/std/bit.cppm
rename to libcxx/modules/std/bit.inc
index 7e2260274abb8a..2a05a8ee46dc4b 100644
--- a/libcxx/modules/std/bit.cppm
+++ b/libcxx/modules/std/bit.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <bit>
-
-export module std:bit;
 export namespace std {
   // [bit.cast], bit_cast
   using std::bit_cast;

diff  --git a/libcxx/modules/std/bitset.cppm b/libcxx/modules/std/bitset.inc
similarity index 92%
rename from libcxx/modules/std/bitset.cppm
rename to libcxx/modules/std/bitset.inc
index 95404c899ef08c..bb528860eb5617 100644
--- a/libcxx/modules/std/bitset.cppm
+++ b/libcxx/modules/std/bitset.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <bitset>
-
-export module std:bitset;
 export namespace std {
   using std::bitset;
 

diff  --git a/libcxx/modules/std/cerrno.cppm b/libcxx/modules/std/cassert.inc
similarity index 89%
rename from libcxx/modules/std/cerrno.cppm
rename to libcxx/modules/std/cassert.inc
index d319956d9e70da..2ab8eb970e7a5e 100644
--- a/libcxx/modules/std/cerrno.cppm
+++ b/libcxx/modules/std/cassert.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <cerrno>
-
-export module std:cerrno;
 export namespace std {
   // This module exports nothing.
 } // namespace std

diff  --git a/libcxx/modules/std/cctype.cppm b/libcxx/modules/std/cctype.inc
similarity index 93%
rename from libcxx/modules/std/cctype.cppm
rename to libcxx/modules/std/cctype.inc
index d91c5c505d399f..075dbbe78198e8 100644
--- a/libcxx/modules/std/cctype.cppm
+++ b/libcxx/modules/std/cctype.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <cctype>
-
-export module std:cctype;
 export namespace std {
   using std::isalnum;
   using std::isalpha;

diff  --git a/libcxx/modules/std/cfloat.cppm b/libcxx/modules/std/cerrno.inc
similarity index 89%
rename from libcxx/modules/std/cfloat.cppm
rename to libcxx/modules/std/cerrno.inc
index daf4f55cfa119f..2ab8eb970e7a5e 100644
--- a/libcxx/modules/std/cfloat.cppm
+++ b/libcxx/modules/std/cerrno.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <cfloat>
-
-export module std:cfloat;
 export namespace std {
   // This module exports nothing.
 } // namespace std

diff  --git a/libcxx/modules/std/cfenv.cppm b/libcxx/modules/std/cfenv.inc
similarity index 93%
rename from libcxx/modules/std/cfenv.cppm
rename to libcxx/modules/std/cfenv.inc
index bb1d314980e5b1..34a8a7afa846f5 100644
--- a/libcxx/modules/std/cfenv.cppm
+++ b/libcxx/modules/std/cfenv.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <cfenv>
-
-export module std:cfenv;
 export namespace std {
   // types
   using std::fenv_t;

diff  --git a/libcxx/modules/std/climits.cppm b/libcxx/modules/std/cfloat.inc
similarity index 89%
rename from libcxx/modules/std/climits.cppm
rename to libcxx/modules/std/cfloat.inc
index 04603b796534aa..2ab8eb970e7a5e 100644
--- a/libcxx/modules/std/climits.cppm
+++ b/libcxx/modules/std/cfloat.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <climits>
-
-export module std:climits;
 export namespace std {
   // This module exports nothing.
 } // namespace std

diff  --git a/libcxx/modules/std/charconv.cppm b/libcxx/modules/std/charconv.inc
similarity index 94%
rename from libcxx/modules/std/charconv.cppm
rename to libcxx/modules/std/charconv.inc
index 0faa546a8d7957..6fee460108d65c 100644
--- a/libcxx/modules/std/charconv.cppm
+++ b/libcxx/modules/std/charconv.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <charconv>
-
-export module std:charconv;
 export namespace std {
 
   // floating-point format for primitive numerical conversion

diff  --git a/libcxx/modules/std/chrono.cppm b/libcxx/modules/std/chrono.inc
similarity index 99%
rename from libcxx/modules/std/chrono.cppm
rename to libcxx/modules/std/chrono.inc
index dbb22650261e94..8ed0b00684e59d 100644
--- a/libcxx/modules/std/chrono.cppm
+++ b/libcxx/modules/std/chrono.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <chrono>
-
-export module std:chrono;
 export namespace std {
 
   namespace chrono {

diff  --git a/libcxx/modules/std/cinttypes.cppm b/libcxx/modules/std/cinttypes.inc
similarity index 93%
rename from libcxx/modules/std/cinttypes.cppm
rename to libcxx/modules/std/cinttypes.inc
index 8758acc6ff91de..2e135926598652 100644
--- a/libcxx/modules/std/cinttypes.cppm
+++ b/libcxx/modules/std/cinttypes.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <cinttypes>
-
-export module std:cinttypes;
 export namespace std {
   using std::imaxdiv_t;
 

diff  --git a/libcxx/modules/std/cassert.cppm b/libcxx/modules/std/climits.inc
similarity index 89%
rename from libcxx/modules/std/cassert.cppm
rename to libcxx/modules/std/climits.inc
index 21dcd1829b4214..2ab8eb970e7a5e 100644
--- a/libcxx/modules/std/cassert.cppm
+++ b/libcxx/modules/std/climits.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <cassert>
-
-export module std:cassert;
 export namespace std {
   // This module exports nothing.
 } // namespace std

diff  --git a/libcxx/modules/std/clocale.cppm b/libcxx/modules/std/clocale.inc
similarity index 82%
rename from libcxx/modules/std/clocale.cppm
rename to libcxx/modules/std/clocale.inc
index 57d983c703ed1a..3efe1595dc05d6 100644
--- a/libcxx/modules/std/clocale.cppm
+++ b/libcxx/modules/std/clocale.inc
@@ -7,19 +7,11 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <__config>
-#ifndef _LIBCPP_HAS_NO_LOCALIZATION
-#  include <clocale>
-#endif
-
-export module std:clocale;
-#ifndef _LIBCPP_HAS_NO_LOCALIZATION
 export namespace std {
+#ifndef _LIBCPP_HAS_NO_LOCALIZATION
   using std::lconv;
 
   using std::localeconv;
   using std::setlocale;
-
-} // namespace std
 #endif // _LIBCPP_HAS_NO_LOCALIZATION
+} // namespace std

diff  --git a/libcxx/modules/std/cmath.cppm b/libcxx/modules/std/cmath.inc
similarity index 99%
rename from libcxx/modules/std/cmath.cppm
rename to libcxx/modules/std/cmath.inc
index 26f6ed99ce456d..0fe887447ad850 100644
--- a/libcxx/modules/std/cmath.cppm
+++ b/libcxx/modules/std/cmath.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <cmath>
-
-export module std:cmath;
 export namespace std {
 
   using std::double_t;

diff  --git a/libcxx/modules/std/codecvt.cppm b/libcxx/modules/std/codecvt.inc
similarity index 83%
rename from libcxx/modules/std/codecvt.cppm
rename to libcxx/modules/std/codecvt.inc
index caa24c4ca47fdc..996036822bb40a 100644
--- a/libcxx/modules/std/codecvt.cppm
+++ b/libcxx/modules/std/codecvt.inc
@@ -7,21 +7,12 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <__config>
-#ifndef _LIBCPP_HAS_NO_LOCALIZATION
-#  include <codecvt>
-#endif
-
-export module std:codecvt;
-#ifndef _LIBCPP_HAS_NO_LOCALIZATION
 export namespace std {
-
+#ifndef _LIBCPP_HAS_NO_LOCALIZATION
   using std::codecvt_mode;
 
   using std::codecvt_utf16;
   using std::codecvt_utf8;
   using std::codecvt_utf8_utf16;
-
-} // namespace std
 #endif // _LIBCPP_HAS_NO_LOCALIZATION
+} // namespace std

diff  --git a/libcxx/modules/std/compare.cppm b/libcxx/modules/std/compare.inc
similarity index 96%
rename from libcxx/modules/std/compare.cppm
rename to libcxx/modules/std/compare.inc
index ebeff411855e61..9d002d301efc3c 100644
--- a/libcxx/modules/std/compare.cppm
+++ b/libcxx/modules/std/compare.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <compare>
-
-export module std:compare;
 export namespace std {
 
   // [cmp.categories], comparison category types

diff  --git a/libcxx/modules/std/complex.cppm b/libcxx/modules/std/complex.inc
similarity index 96%
rename from libcxx/modules/std/complex.cppm
rename to libcxx/modules/std/complex.inc
index b3207db2c17c97..7a553242371c5f 100644
--- a/libcxx/modules/std/complex.cppm
+++ b/libcxx/modules/std/complex.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <complex>
-
-export module std:complex;
 export namespace std {
 
   // [complex], class template complex

diff  --git a/libcxx/modules/std/concepts.cppm b/libcxx/modules/std/concepts.inc
similarity index 97%
rename from libcxx/modules/std/concepts.cppm
rename to libcxx/modules/std/concepts.inc
index 6c3333eb27fea1..29f4e2788e9ab2 100644
--- a/libcxx/modules/std/concepts.cppm
+++ b/libcxx/modules/std/concepts.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <concepts>
-
-export module std:concepts;
 export namespace std {
 
   // [concepts.lang], language-related concepts

diff  --git a/libcxx/modules/std/condition_variable.cppm b/libcxx/modules/std/condition_variable.inc
similarity index 90%
rename from libcxx/modules/std/condition_variable.cppm
rename to libcxx/modules/std/condition_variable.inc
index 4528c4150b8b13..95d00f3c0e5a2b 100644
--- a/libcxx/modules/std/condition_variable.cppm
+++ b/libcxx/modules/std/condition_variable.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <condition_variable>
-
-export module std:condition_variable;
 export namespace std {
 
   // [thread.condition.condvar], class condition_variable

diff  --git a/libcxx/modules/std/coroutine.cppm b/libcxx/modules/std/coroutine.inc
similarity index 92%
rename from libcxx/modules/std/coroutine.cppm
rename to libcxx/modules/std/coroutine.inc
index 26f141fa18b32d..5d992f29a1e2ed 100644
--- a/libcxx/modules/std/coroutine.cppm
+++ b/libcxx/modules/std/coroutine.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <coroutine>
-#include <functional>
-export module std:coroutine;
 export namespace std {
 
   // [coroutine.traits], coroutine traits

diff  --git a/libcxx/modules/std/csetjmp.cppm b/libcxx/modules/std/csetjmp.inc
similarity index 89%
rename from libcxx/modules/std/csetjmp.cppm
rename to libcxx/modules/std/csetjmp.inc
index ba97c0c4aa534d..68e226c8b7f1cc 100644
--- a/libcxx/modules/std/csetjmp.cppm
+++ b/libcxx/modules/std/csetjmp.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <csetjmp>
-
-export module std:csetjmp;
 export namespace std {
   using std::jmp_buf;
   using std::longjmp;

diff  --git a/libcxx/modules/std/csignal.cppm b/libcxx/modules/std/csignal.inc
similarity index 90%
rename from libcxx/modules/std/csignal.cppm
rename to libcxx/modules/std/csignal.inc
index 90a6c562bc8cac..b57e8edc6c0946 100644
--- a/libcxx/modules/std/csignal.cppm
+++ b/libcxx/modules/std/csignal.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <csignal>
-
-export module std:csignal;
 export namespace std {
   using std::sig_atomic_t;
 

diff  --git a/libcxx/modules/std/cstdarg.cppm b/libcxx/modules/std/cstdarg.inc
similarity index 89%
rename from libcxx/modules/std/cstdarg.cppm
rename to libcxx/modules/std/cstdarg.inc
index 4b971b7fc12756..2b7309c94ed268 100644
--- a/libcxx/modules/std/cstdarg.cppm
+++ b/libcxx/modules/std/cstdarg.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <cstdarg>
-
-export module std:cstdarg;
 export namespace std {
   using std::va_list;
 } // namespace std

diff  --git a/libcxx/modules/std/cstddef.cppm b/libcxx/modules/std/cstddef.inc
similarity index 94%
rename from libcxx/modules/std/cstddef.cppm
rename to libcxx/modules/std/cstddef.inc
index aecee6e33aebdc..2b9ab0c4707467 100644
--- a/libcxx/modules/std/cstddef.cppm
+++ b/libcxx/modules/std/cstddef.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <cstddef>
-
-export module std:cstddef;
 export namespace std {
   using std::max_align_t;
   using std::nullptr_t;

diff  --git a/libcxx/modules/std/cstdint.cppm b/libcxx/modules/std/cstdint.inc
similarity index 96%
rename from libcxx/modules/std/cstdint.cppm
rename to libcxx/modules/std/cstdint.inc
index fdf87130580bcd..f6de4472218dac 100644
--- a/libcxx/modules/std/cstdint.cppm
+++ b/libcxx/modules/std/cstdint.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <cstdint>
-
-export module std:cstdint;
 export namespace std {
   // signed
   using std::int8_t _LIBCPP_USING_IF_EXISTS;

diff  --git a/libcxx/modules/std/cstdio.cppm b/libcxx/modules/std/cstdio.inc
similarity index 96%
rename from libcxx/modules/std/cstdio.cppm
rename to libcxx/modules/std/cstdio.inc
index b5b94cefdef1b3..eec8170e079175 100644
--- a/libcxx/modules/std/cstdio.cppm
+++ b/libcxx/modules/std/cstdio.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <cstdio>
-
-export module std:cstdio;
 export namespace std {
   using std::FILE;
   using std::fpos_t;

diff  --git a/libcxx/modules/std/cstdlib.cppm b/libcxx/modules/std/cstdlib.inc
similarity index 96%
rename from libcxx/modules/std/cstdlib.cppm
rename to libcxx/modules/std/cstdlib.inc
index 4d1f331e37a13c..11c7e8670b057c 100644
--- a/libcxx/modules/std/cstdlib.cppm
+++ b/libcxx/modules/std/cstdlib.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <cstdlib>
-
-export module std:cstdlib;
 export namespace std {
   using std::div_t;
   using std::ldiv_t;

diff  --git a/libcxx/modules/std/cstring.cppm b/libcxx/modules/std/cstring.inc
similarity index 94%
rename from libcxx/modules/std/cstring.cppm
rename to libcxx/modules/std/cstring.inc
index 44b3dcf04d91b2..d21714b787c812 100644
--- a/libcxx/modules/std/cstring.cppm
+++ b/libcxx/modules/std/cstring.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <cstring>
-
-export module std:cstring;
 export namespace std {
   using std::size_t;
 

diff  --git a/libcxx/modules/std/ctime.cppm b/libcxx/modules/std/ctime.inc
similarity index 93%
rename from libcxx/modules/std/ctime.cppm
rename to libcxx/modules/std/ctime.inc
index e63bd23a429868..c407ffc35e3fe3 100644
--- a/libcxx/modules/std/ctime.cppm
+++ b/libcxx/modules/std/ctime.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <ctime>
-
-export module std:ctime;
 export namespace std {
   using std::clock_t;
   using std::size_t;

diff  --git a/libcxx/modules/std/cuchar.cppm b/libcxx/modules/std/cuchar.inc
similarity index 91%
rename from libcxx/modules/std/cuchar.cppm
rename to libcxx/modules/std/cuchar.inc
index c3f8c41f0931ce..fd80110d11ee84 100644
--- a/libcxx/modules/std/cuchar.cppm
+++ b/libcxx/modules/std/cuchar.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <cuchar>
-
-export module std:cuchar;
 export namespace std {
   // Note the Standard does not mark these symbols optional, but libc++'s header
   // does. So this seems strictly not to be conforming.
@@ -21,7 +17,7 @@ export namespace std {
   // size_t is conditionally here, but always present in cstddef.cppm. To avoid
   // conflicing declarations omit the using here.
 
-#  if !defined(_LIBCPP_HAS_NO_C8RTOMB_MBRTOC8)
+#if !defined(_LIBCPP_HAS_NO_C8RTOMB_MBRTOC8)
   using std::mbrtoc8 _LIBCPP_USING_IF_EXISTS;
   using std::c8rtomb _LIBCPP_USING_IF_EXISTS;
 #endif

diff  --git a/libcxx/modules/std/cwchar.cppm b/libcxx/modules/std/cwchar.inc
similarity index 94%
rename from libcxx/modules/std/cwchar.cppm
rename to libcxx/modules/std/cwchar.inc
index 9be68a83e4bb94..6818c46b48ef31 100644
--- a/libcxx/modules/std/cwchar.cppm
+++ b/libcxx/modules/std/cwchar.inc
@@ -7,15 +7,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <__config>
-#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
-#  include <cwchar>
-#endif
-
-export module std:cwchar;
-#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 export namespace std {
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
   using std::mbstate_t;
   using std::size_t;
   using std::wint_t;
@@ -83,6 +76,5 @@ export namespace std {
   using std::mbsrtowcs;
   using std::wcrtomb;
   using std::wcsrtombs;
-
-} // namespace std
 #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
+} // namespace std

diff  --git a/libcxx/modules/std/cwctype.cppm b/libcxx/modules/std/cwctype.inc
similarity index 88%
rename from libcxx/modules/std/cwctype.cppm
rename to libcxx/modules/std/cwctype.inc
index aae5e8d9d7008b..70e6cf3f113374 100644
--- a/libcxx/modules/std/cwctype.cppm
+++ b/libcxx/modules/std/cwctype.inc
@@ -7,15 +7,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <__config>
-#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
-#  include <cwctype>
-#endif
-
-export module std:cwctype;
-#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 export namespace std {
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
   using std::wctrans_t;
   using std::wctype_t;
   using std::wint_t;
@@ -38,5 +31,5 @@ export namespace std {
   using std::towupper;
   using std::wctrans;
   using std::wctype;
-} // namespace std
 #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
+} // namespace std

diff  --git a/libcxx/modules/std/deque.cppm b/libcxx/modules/std/deque.inc
similarity index 93%
rename from libcxx/modules/std/deque.cppm
rename to libcxx/modules/std/deque.inc
index ec980488aede87..5abf88816a98ad 100644
--- a/libcxx/modules/std/deque.cppm
+++ b/libcxx/modules/std/deque.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <deque>
-
-export module std:deque;
 export namespace std {
   // [deque], class template deque
   using std::deque;

diff  --git a/libcxx/modules/std/exception.cppm b/libcxx/modules/std/exception.inc
similarity index 93%
rename from libcxx/modules/std/exception.cppm
rename to libcxx/modules/std/exception.inc
index 9e5a06764cc37f..8e802c7065e0f5 100644
--- a/libcxx/modules/std/exception.cppm
+++ b/libcxx/modules/std/exception.inc
@@ -7,9 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <exception>
-export module std:exception;
 export namespace std {
   using std::bad_exception;
   using std::current_exception;

diff  --git a/libcxx/modules/std/execution.cppm b/libcxx/modules/std/execution.inc
similarity index 95%
rename from libcxx/modules/std/execution.cppm
rename to libcxx/modules/std/execution.inc
index e0996f33d41523..b0a3b17fe3e4c6 100644
--- a/libcxx/modules/std/execution.cppm
+++ b/libcxx/modules/std/execution.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <execution>
-
-export module std:execution;
 export namespace std {
   // [execpol.type], execution policy type trait
   using std::is_execution_policy;

diff  --git a/libcxx/modules/std/expected.cppm b/libcxx/modules/std/expected.inc
similarity index 93%
rename from libcxx/modules/std/expected.cppm
rename to libcxx/modules/std/expected.inc
index abf7fca09fe498..1595230123dea8 100644
--- a/libcxx/modules/std/expected.cppm
+++ b/libcxx/modules/std/expected.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <expected>
-
-export module std:expected;
 export namespace std {
   // [expected.unexpected], class template unexpected
   using std::unexpected;

diff  --git a/libcxx/modules/std/filesystem.cppm b/libcxx/modules/std/filesystem.inc
similarity index 98%
rename from libcxx/modules/std/filesystem.cppm
rename to libcxx/modules/std/filesystem.inc
index c6dac368a1cd58..565705cfb4eb8c 100644
--- a/libcxx/modules/std/filesystem.cppm
+++ b/libcxx/modules/std/filesystem.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <filesystem>
-
-export module std:filesystem;
 export namespace std::filesystem {
   // [fs.class.path], paths
   using std::filesystem::path;

diff  --git a/libcxx/modules/std/flat_map.cppm b/libcxx/modules/std/flat_map.inc
similarity index 83%
rename from libcxx/modules/std/flat_map.cppm
rename to libcxx/modules/std/flat_map.inc
index ff26fe46ce7eec..83cd20ad618946 100644
--- a/libcxx/modules/std/flat_map.cppm
+++ b/libcxx/modules/std/flat_map.inc
@@ -7,13 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#if __has_include(<flat_map>)
-#  error "include this header unconditionally and uncomment the exported symbols"
-#  include <flat_map>
-#endif
-
-export module std:flat_map;
 export namespace std {
 #if 0
   // [flat.map], class template flat_­map

diff  --git a/libcxx/modules/std/flat_set.cppm b/libcxx/modules/std/flat_set.inc
similarity index 82%
rename from libcxx/modules/std/flat_set.cppm
rename to libcxx/modules/std/flat_set.inc
index b40d1583f70167..a86cc1eae02a62 100644
--- a/libcxx/modules/std/flat_set.cppm
+++ b/libcxx/modules/std/flat_set.inc
@@ -7,13 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#if __has_include(<flat_set>)
-#  error "include this header unconditionally and uncomment the exported symbols"
-#  include <flat_set>
-#endif
-
-export module std:flat_set;
 export namespace std {
 #if 0
   // [flat.set], class template flat_­set

diff  --git a/libcxx/modules/std/format.cppm b/libcxx/modules/std/format.inc
similarity index 97%
rename from libcxx/modules/std/format.cppm
rename to libcxx/modules/std/format.inc
index cb8b46151fdd43..ae7de95495cf8c 100644
--- a/libcxx/modules/std/format.cppm
+++ b/libcxx/modules/std/format.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <format>
-
-export module std:format;
 export namespace std {
   // [format.context], class template basic_format_context
   using std::basic_format_context;

diff  --git a/libcxx/modules/std/forward_list.cppm b/libcxx/modules/std/forward_list.inc
similarity index 91%
rename from libcxx/modules/std/forward_list.cppm
rename to libcxx/modules/std/forward_list.inc
index 1ef8be9083e9c7..c9585b5523b369 100644
--- a/libcxx/modules/std/forward_list.cppm
+++ b/libcxx/modules/std/forward_list.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <forward_list>
-
-export module std:forward_list;
 export namespace std {
   // [forward.list], class template forward_list
   using std::forward_list;

diff  --git a/libcxx/modules/std/fstream.cppm b/libcxx/modules/std/fstream.inc
similarity index 89%
rename from libcxx/modules/std/fstream.cppm
rename to libcxx/modules/std/fstream.inc
index 11bdcfb4bb9375..4b6abf658db2e9 100644
--- a/libcxx/modules/std/fstream.cppm
+++ b/libcxx/modules/std/fstream.inc
@@ -7,15 +7,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <__config>
-#ifndef _LIBCPP_HAS_NO_LOCALIZATION
-#  include <fstream>
-#endif
-
-export module std:fstream;
-#ifndef _LIBCPP_HAS_NO_LOCALIZATION
 export namespace std {
+#ifndef _LIBCPP_HAS_NO_LOCALIZATION
   using std::basic_filebuf;
 
   using std::swap;
@@ -45,5 +38,5 @@ export namespace std {
 #  ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
   using std::wfstream;
 #  endif
-} // namespace std
 #endif // _LIBCPP_HAS_NO_LOCALIZATION
+} // namespace std

diff  --git a/libcxx/modules/std/functional.cppm b/libcxx/modules/std/functional.inc
similarity index 97%
rename from libcxx/modules/std/functional.cppm
rename to libcxx/modules/std/functional.inc
index 9760933989576f..f8a29e2f058f8f 100644
--- a/libcxx/modules/std/functional.cppm
+++ b/libcxx/modules/std/functional.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <functional>
-
-export module std:functional;
 export namespace std {
   // [func.invoke], invoke
   using std::invoke;

diff  --git a/libcxx/modules/std/future.cppm b/libcxx/modules/std/future.inc
similarity index 96%
rename from libcxx/modules/std/future.cppm
rename to libcxx/modules/std/future.inc
index 69f9eb53c6695c..8ff034de49d961 100644
--- a/libcxx/modules/std/future.cppm
+++ b/libcxx/modules/std/future.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <future>
-
-export module std:future;
 export namespace std {
   using std::future_errc;
   using std::future_status;

diff  --git a/libcxx/modules/std/generator.cppm b/libcxx/modules/std/generator.cppm
deleted file mode 100644
index c67f5d012679d3..00000000000000
--- a/libcxx/modules/std/generator.cppm
+++ /dev/null
@@ -1,21 +0,0 @@
-// -*- C++ -*-
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-module;
-#if __has_include(<generator>)
-#  error "include this header unconditionally and uncomment the exported symbols"
-#  include <generator>
-#endif
-
-export module std:generator;
-export namespace std {
-#if 0
-  using std::generator;
-#endif
-} // namespace std

diff  --git a/libcxx/modules/std/generator.inc b/libcxx/modules/std/generator.inc
new file mode 100644
index 00000000000000..43fb0daf5c6593
--- /dev/null
+++ b/libcxx/modules/std/generator.inc
@@ -0,0 +1,14 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+export namespace std {
+#if 0
+  using std::generator;
+#endif
+} // namespace std

diff  --git a/libcxx/modules/std/hazard_pointer.cppm b/libcxx/modules/std/hazard_pointer.inc
similarity index 80%
rename from libcxx/modules/std/hazard_pointer.cppm
rename to libcxx/modules/std/hazard_pointer.inc
index 84b83f55b31fb3..e56f4d0bf43630 100644
--- a/libcxx/modules/std/hazard_pointer.cppm
+++ b/libcxx/modules/std/hazard_pointer.inc
@@ -7,13 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#if __has_include(<hazard_pointer>)
-#  error "include this header unconditionally and uncomment the exported symbols"
-#  include <hazard_pointer>
-#endif
-
-export module std:hazard_pointer;
 export namespace std {
 #if 0
 #  if _LIBCPP_STD_VER >= 23

diff  --git a/libcxx/modules/std/initializer_list.cppm b/libcxx/modules/std/initializer_list.inc
similarity index 88%
rename from libcxx/modules/std/initializer_list.cppm
rename to libcxx/modules/std/initializer_list.inc
index 8e041f747cb5d9..1dbeb220ca3c5f 100644
--- a/libcxx/modules/std/initializer_list.cppm
+++ b/libcxx/modules/std/initializer_list.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <initializer_list>
-
-export module std:initializer_list;
 export namespace std {
   using std::initializer_list;
 

diff  --git a/libcxx/modules/std/iomanip.cppm b/libcxx/modules/std/iomanip.inc
similarity index 86%
rename from libcxx/modules/std/iomanip.cppm
rename to libcxx/modules/std/iomanip.inc
index 5f795c070c8deb..35a52efcd20b0b 100644
--- a/libcxx/modules/std/iomanip.cppm
+++ b/libcxx/modules/std/iomanip.inc
@@ -7,15 +7,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <__config>
-#ifndef _LIBCPP_HAS_NO_LOCALIZATION
-#  include <iomanip>
-#endif
-
-export module std:iomanip;
-#ifndef _LIBCPP_HAS_NO_LOCALIZATION
 export namespace std {
+#ifndef _LIBCPP_HAS_NO_LOCALIZATION
   using std::get_money;
   using std::get_time;
   using std::put_money;
@@ -28,5 +21,5 @@ export namespace std {
   using std::setw;
 
   using std::quoted;
-} // namespace std
 #endif // _LIBCPP_HAS_NO_LOCALIZATION
+} // namespace std

diff  --git a/libcxx/modules/std/ios.cppm b/libcxx/modules/std/ios.inc
similarity index 94%
rename from libcxx/modules/std/ios.cppm
rename to libcxx/modules/std/ios.inc
index 5dc7eb4172e6c5..eeed5398c5a684 100644
--- a/libcxx/modules/std/ios.cppm
+++ b/libcxx/modules/std/ios.inc
@@ -7,15 +7,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <__config>
-#ifndef _LIBCPP_HAS_NO_LOCALIZATION
-#  include <ios>
-#endif
-
-export module std:ios;
-#ifndef _LIBCPP_HAS_NO_LOCALIZATION
 export namespace std {
+#ifndef _LIBCPP_HAS_NO_LOCALIZATION
   using std::fpos;
   // based on [tab:fpos.operations]
   using std::operator!=; // Note not affected by P1614, seems like a bug.
@@ -79,5 +72,5 @@ export namespace std {
 #  ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
   using std::wios;
 #  endif
-} // namespace std
 #endif // _LIBCPP_HAS_NO_LOCALIZATION
+} // namespace std

diff  --git a/libcxx/modules/std/iosfwd.cppm b/libcxx/modules/std/iosfwd.inc
similarity index 92%
rename from libcxx/modules/std/iosfwd.cppm
rename to libcxx/modules/std/iosfwd.inc
index 3ba00d5e9ca099..aba7f1e419803e 100644
--- a/libcxx/modules/std/iosfwd.cppm
+++ b/libcxx/modules/std/iosfwd.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <iosfwd>
-
-export module std:iosfwd;
 export namespace std {
   using std::streampos;
 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS

diff  --git a/libcxx/modules/std/iostream.cppm b/libcxx/modules/std/iostream.inc
similarity index 85%
rename from libcxx/modules/std/iostream.cppm
rename to libcxx/modules/std/iostream.inc
index 3b80f8324a88b2..d6e20364960575 100644
--- a/libcxx/modules/std/iostream.cppm
+++ b/libcxx/modules/std/iostream.inc
@@ -7,15 +7,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <__config>
-#ifndef _LIBCPP_HAS_NO_LOCALIZATION
-#  include <iostream>
-#endif
-
-export module std:iostream;
-#ifndef _LIBCPP_HAS_NO_LOCALIZATION
 export namespace std {
+#ifndef _LIBCPP_HAS_NO_LOCALIZATION
   using std::cerr;
   using std::cin;
   using std::clog;
@@ -27,5 +20,5 @@ export namespace std {
   using std::wclog;
   using std::wcout;
 #  endif
-} // namespace std
 #endif // _LIBCPP_HAS_NO_LOCALIZATION
+} // namespace std

diff  --git a/libcxx/modules/std/istream.cppm b/libcxx/modules/std/istream.inc
similarity index 86%
rename from libcxx/modules/std/istream.cppm
rename to libcxx/modules/std/istream.inc
index ad18977d2bde99..fdb1854014036f 100644
--- a/libcxx/modules/std/istream.cppm
+++ b/libcxx/modules/std/istream.inc
@@ -7,15 +7,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <__config>
-#ifndef _LIBCPP_HAS_NO_LOCALIZATION
-#  include <istream>
-#endif
-
-export module std:istream;
-#ifndef _LIBCPP_HAS_NO_LOCALIZATION
 export namespace std {
+#ifndef _LIBCPP_HAS_NO_LOCALIZATION
   using std::basic_istream;
 
   using std::istream;
@@ -33,5 +26,5 @@ export namespace std {
   using std::ws;
 
   using std::operator>>;
-} // namespace std
 #endif // _LIBCPP_HAS_NO_LOCALIZATION
+} // namespace std

diff  --git a/libcxx/modules/std/iterator.cppm b/libcxx/modules/std/iterator.inc
similarity index 99%
rename from libcxx/modules/std/iterator.cppm
rename to libcxx/modules/std/iterator.inc
index 65fa363181eaa5..10c63d74e6e05e 100644
--- a/libcxx/modules/std/iterator.cppm
+++ b/libcxx/modules/std/iterator.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <iterator>
-
-export module std:iterator;
 export namespace std {
   // [iterator.assoc.types], associated types
   // [incrementable.traits], incrementable traits

diff  --git a/libcxx/modules/std/latch.cppm b/libcxx/modules/std/latch.inc
similarity index 89%
rename from libcxx/modules/std/latch.cppm
rename to libcxx/modules/std/latch.inc
index dfafd79501e466..5afb8ff6120656 100644
--- a/libcxx/modules/std/latch.cppm
+++ b/libcxx/modules/std/latch.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <latch>
-
-export module std:latch;
 export namespace std {
   using std::latch;
 } // namespace std

diff  --git a/libcxx/modules/std/limits.cppm b/libcxx/modules/std/limits.inc
similarity index 92%
rename from libcxx/modules/std/limits.cppm
rename to libcxx/modules/std/limits.inc
index 54ddccd3ff234b..9aae993baa6f7e 100644
--- a/libcxx/modules/std/limits.cppm
+++ b/libcxx/modules/std/limits.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <limits>
-
-export module std:limits;
 export namespace std {
   // [fp.style], floating-point type properties
   using std::float_denorm_style;

diff  --git a/libcxx/modules/std/list.cppm b/libcxx/modules/std/list.inc
similarity index 93%
rename from libcxx/modules/std/list.cppm
rename to libcxx/modules/std/list.inc
index eff83c95e49f86..f38094c9b8a7c4 100644
--- a/libcxx/modules/std/list.cppm
+++ b/libcxx/modules/std/list.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <list>
-
-export module std:list;
 export namespace std {
   // [list], class template list
   using std::list;

diff  --git a/libcxx/modules/std/locale.cppm b/libcxx/modules/std/locale.inc
similarity index 90%
rename from libcxx/modules/std/locale.cppm
rename to libcxx/modules/std/locale.inc
index d983fd1eed0ebe..8e0018f6042538 100644
--- a/libcxx/modules/std/locale.cppm
+++ b/libcxx/modules/std/locale.inc
@@ -7,14 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <__config>
-#ifndef _LIBCPP_HAS_NO_LOCALIZATION
-#  include <locale>
-#endif
-
-export module std:locale;
-#ifndef _LIBCPP_HAS_NO_LOCALIZATION
 export namespace std {
   // [locale], locale
   using std::has_facet;
@@ -80,4 +72,3 @@ export namespace std {
   // [depr.conversions.string]
   using std::wstring_convert;
 } // namespace std
-#endif // _LIBCPP_HAS_NO_LOCALIZATION

diff  --git a/libcxx/modules/std/map.cppm b/libcxx/modules/std/map.inc
similarity index 94%
rename from libcxx/modules/std/map.cppm
rename to libcxx/modules/std/map.inc
index 31353d1df9e497..ed154e3e8c6fd8 100644
--- a/libcxx/modules/std/map.cppm
+++ b/libcxx/modules/std/map.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <map>
-
-export module std:map;
 export namespace std {
   // [map], class template map
   using std::map;

diff  --git a/libcxx/modules/std/mdspan.cppm b/libcxx/modules/std/mdspan.inc
similarity index 94%
rename from libcxx/modules/std/mdspan.cppm
rename to libcxx/modules/std/mdspan.inc
index d92024d9a77a3d..37580eaa458b41 100644
--- a/libcxx/modules/std/mdspan.cppm
+++ b/libcxx/modules/std/mdspan.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <mdspan>
-
-export module std:mdspan;
 export namespace std {
   // [mdspan.extents], class template extents
   using std::extents;

diff  --git a/libcxx/modules/std/memory.cppm b/libcxx/modules/std/memory.inc
similarity index 99%
rename from libcxx/modules/std/memory.cppm
rename to libcxx/modules/std/memory.inc
index 46a88cba018e84..06af546de537e7 100644
--- a/libcxx/modules/std/memory.cppm
+++ b/libcxx/modules/std/memory.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <memory>
-
-export module std:memory;
 export namespace std {
   // [pointer.traits], pointer traits
   using std::pointer_traits;

diff  --git a/libcxx/modules/std/memory_resource.cppm b/libcxx/modules/std/memory_resource.inc
similarity index 93%
rename from libcxx/modules/std/memory_resource.cppm
rename to libcxx/modules/std/memory_resource.inc
index 3c0be56d1eae76..740179baea273b 100644
--- a/libcxx/modules/std/memory_resource.cppm
+++ b/libcxx/modules/std/memory_resource.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <memory_resource>
-
-export module std:memory_resource;
 export namespace std::pmr {
   // [mem.res.class], class memory_resource
   using std::pmr::memory_resource;

diff  --git a/libcxx/modules/std/mutex.cppm b/libcxx/modules/std/mutex.inc
similarity index 95%
rename from libcxx/modules/std/mutex.cppm
rename to libcxx/modules/std/mutex.inc
index fcd087c0e3615d..fa55324c56c4c9 100644
--- a/libcxx/modules/std/mutex.cppm
+++ b/libcxx/modules/std/mutex.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <mutex>
-
-export module std:mutex;
 export namespace std {
   // [thread.mutex.class], class mutex
   using std::mutex;

diff  --git a/libcxx/modules/std/new.cppm b/libcxx/modules/std/new.inc
similarity index 92%
rename from libcxx/modules/std/new.cppm
rename to libcxx/modules/std/new.inc
index bc8eb700d445ab..31c49057d0d286 100644
--- a/libcxx/modules/std/new.cppm
+++ b/libcxx/modules/std/new.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <new>
-
-export module std:__new; // Note new is a keyword and not a valid identifier
 export namespace std {
   // [alloc.errors], storage allocation errors
   using std::bad_alloc;

diff  --git a/libcxx/modules/std/numbers.cppm b/libcxx/modules/std/numbers.inc
similarity index 95%
rename from libcxx/modules/std/numbers.cppm
rename to libcxx/modules/std/numbers.inc
index 6b9a62a7c7a924..2f55f442b18dcc 100644
--- a/libcxx/modules/std/numbers.cppm
+++ b/libcxx/modules/std/numbers.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <numbers>
-
-export module std:numbers;
 export namespace std::numbers {
   using std::numbers::e_v;
   using std::numbers::egamma_v;

diff  --git a/libcxx/modules/std/numeric.cppm b/libcxx/modules/std/numeric.inc
similarity index 96%
rename from libcxx/modules/std/numeric.cppm
rename to libcxx/modules/std/numeric.inc
index a8c513ee78b74f..d2b7688d4e5f10 100644
--- a/libcxx/modules/std/numeric.cppm
+++ b/libcxx/modules/std/numeric.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <numeric>
-
-export module std:numeric;
 export namespace std {
   // [accumulate], accumulate
   using std::accumulate;

diff  --git a/libcxx/modules/std/optional.cppm b/libcxx/modules/std/optional.inc
similarity index 94%
rename from libcxx/modules/std/optional.cppm
rename to libcxx/modules/std/optional.inc
index 4ebc503d34b09c..0f812bc0e24a47 100644
--- a/libcxx/modules/std/optional.cppm
+++ b/libcxx/modules/std/optional.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <optional>
-
-export module std:optional;
 export namespace std {
   // [optional.optional], class template optional
   using std::optional;

diff  --git a/libcxx/modules/std/ostream.cppm b/libcxx/modules/std/ostream.inc
similarity index 89%
rename from libcxx/modules/std/ostream.cppm
rename to libcxx/modules/std/ostream.inc
index 0b15048666a593..e8989788b7a544 100644
--- a/libcxx/modules/std/ostream.cppm
+++ b/libcxx/modules/std/ostream.inc
@@ -7,15 +7,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <__config>
-#ifndef _LIBCPP_HAS_NO_LOCALIZATION
-#  include <ostream>
-#endif
-
-export module std:ostream;
-#ifndef _LIBCPP_HAS_NO_LOCALIZATION
 export namespace std {
+#ifndef _LIBCPP_HAS_NO_LOCALIZATION
   using std::basic_ostream;
 
   using std::ostream;
@@ -42,5 +35,5 @@ export namespace std {
   using std::vprint_nonunicode;
   using std::vprint_unicode;
 #  endif
-} // namespace std
 #endif // _LIBCPP_HAS_NO_LOCALIZATION
+} // namespace std

diff  --git a/libcxx/modules/std/print.cppm b/libcxx/modules/std/print.inc
similarity index 91%
rename from libcxx/modules/std/print.cppm
rename to libcxx/modules/std/print.inc
index 9d089a6a5fa686..32304d22926ca9 100644
--- a/libcxx/modules/std/print.cppm
+++ b/libcxx/modules/std/print.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <print>
-
-export module std:print;
 export namespace std {
   // [print.fun], print functions
   using std::print;

diff  --git a/libcxx/modules/std/queue.cppm b/libcxx/modules/std/queue.inc
similarity index 93%
rename from libcxx/modules/std/queue.cppm
rename to libcxx/modules/std/queue.inc
index 8632ee2e42a9f1..d2fb18709c7097 100644
--- a/libcxx/modules/std/queue.cppm
+++ b/libcxx/modules/std/queue.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <queue>
-
-export module std:queue;
 export namespace std {
   // [queue], class template queue
   using std::queue;

diff  --git a/libcxx/modules/std/random.cppm b/libcxx/modules/std/random.inc
similarity index 98%
rename from libcxx/modules/std/random.cppm
rename to libcxx/modules/std/random.inc
index 43137b7600dcd7..87758fa949e1f5 100644
--- a/libcxx/modules/std/random.cppm
+++ b/libcxx/modules/std/random.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <random>
-
-export module std:random;
 export namespace std {
   // [rand.req.urng], uniform random bit generator requirements
   using std::uniform_random_bit_generator;

diff  --git a/libcxx/modules/std/ranges.cppm b/libcxx/modules/std/ranges.inc
similarity index 99%
rename from libcxx/modules/std/ranges.cppm
rename to libcxx/modules/std/ranges.inc
index cf4c252834f0d7..a6b1bf5496251a 100644
--- a/libcxx/modules/std/ranges.cppm
+++ b/libcxx/modules/std/ranges.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <ranges>
-
-export module std:ranges;
 export namespace std {
   namespace ranges {
     inline namespace __cpo {

diff  --git a/libcxx/modules/std/ratio.cppm b/libcxx/modules/std/ratio.inc
similarity index 96%
rename from libcxx/modules/std/ratio.cppm
rename to libcxx/modules/std/ratio.inc
index 410b9cf153bf48..4e1d4c61e70721 100644
--- a/libcxx/modules/std/ratio.cppm
+++ b/libcxx/modules/std/ratio.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <ratio>
-
-export module std:ratio;
 export namespace std {
   // [ratio.ratio], class template ratio
   using std::ratio;

diff  --git a/libcxx/modules/std/rcu.cppm b/libcxx/modules/std/rcu.inc
similarity index 81%
rename from libcxx/modules/std/rcu.cppm
rename to libcxx/modules/std/rcu.inc
index fb5e5e1a5066a9..abf5afad30c138 100644
--- a/libcxx/modules/std/rcu.cppm
+++ b/libcxx/modules/std/rcu.inc
@@ -7,13 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#if __has_include(<rcu>)
-#  error "include this header unconditionally and uncomment the exported symbols"
-#  include <rcu>
-#endif
-
-export module std:rcu;
 export namespace std {
 #if 0
 #  if _LIBCPP_STD_VER >= 23

diff  --git a/libcxx/modules/std/regex.cppm b/libcxx/modules/std/regex.inc
similarity index 95%
rename from libcxx/modules/std/regex.cppm
rename to libcxx/modules/std/regex.inc
index 7c23e6309c501b..8217e34bc22c84 100644
--- a/libcxx/modules/std/regex.cppm
+++ b/libcxx/modules/std/regex.inc
@@ -7,15 +7,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <__config>
-#ifndef _LIBCPP_HAS_NO_LOCALIZATION
-#  include <regex>
-#endif
-
-export module std:regex;
-#ifndef _LIBCPP_HAS_NO_LOCALIZATION
 export namespace std {
+#ifndef _LIBCPP_HAS_NO_LOCALIZATION
   // [re.const], regex constants
   namespace regex_constants {
     using std::regex_constants::error_type;
@@ -119,6 +112,6 @@ export namespace std {
     using std::pmr::wcmatch;
     using std::pmr::wsmatch;
 #  endif
-  } // namespace pmr
-} // namespace std
+  }    // namespace pmr
 #endif // _LIBCPP_HAS_NO_LOCALIZATION
+} // namespace std

diff  --git a/libcxx/modules/std/scoped_allocator.cppm b/libcxx/modules/std/scoped_allocator.inc
similarity index 89%
rename from libcxx/modules/std/scoped_allocator.cppm
rename to libcxx/modules/std/scoped_allocator.inc
index f198db90d10206..91c9694db28f91 100644
--- a/libcxx/modules/std/scoped_allocator.cppm
+++ b/libcxx/modules/std/scoped_allocator.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <scoped_allocator>
-
-export module std:scoped_allocator;
 export namespace std {
   // class template scoped_allocator_adaptor
   using std::scoped_allocator_adaptor;

diff  --git a/libcxx/modules/std/semaphore.cppm b/libcxx/modules/std/semaphore.inc
similarity index 90%
rename from libcxx/modules/std/semaphore.cppm
rename to libcxx/modules/std/semaphore.inc
index 7b81460ed26372..bc8d905ac28163 100644
--- a/libcxx/modules/std/semaphore.cppm
+++ b/libcxx/modules/std/semaphore.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <semaphore>
-
-export module std:semaphore;
 export namespace std {
   // [thread.sema.cnt], class template counting_semaphore
   using std::counting_semaphore;

diff  --git a/libcxx/modules/std/set.cppm b/libcxx/modules/std/set.inc
similarity index 94%
rename from libcxx/modules/std/set.cppm
rename to libcxx/modules/std/set.inc
index 19a2734604d157..a8db792b4b3815 100644
--- a/libcxx/modules/std/set.cppm
+++ b/libcxx/modules/std/set.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <set>
-
-export module std:set;
 export namespace std {
   // [set], class template set
   using std::set;

diff  --git a/libcxx/modules/std/shared_mutex.cppm b/libcxx/modules/std/shared_mutex.inc
similarity index 91%
rename from libcxx/modules/std/shared_mutex.cppm
rename to libcxx/modules/std/shared_mutex.inc
index 36c0f18399ae4a..2b0782e718ea51 100644
--- a/libcxx/modules/std/shared_mutex.cppm
+++ b/libcxx/modules/std/shared_mutex.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <shared_mutex>
-
-export module std:shared_mutex;
 export namespace std {
   // [thread.sharedmutex.class], class shared_­mutex
   using std::shared_mutex;

diff  --git a/libcxx/modules/std/source_location.cppm b/libcxx/modules/std/source_location.inc
similarity index 86%
rename from libcxx/modules/std/source_location.cppm
rename to libcxx/modules/std/source_location.inc
index 0f6aee59ddecbf..750ab164a38de1 100644
--- a/libcxx/modules/std/source_location.cppm
+++ b/libcxx/modules/std/source_location.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <source_location>
-
-export module std:source_location;
 export namespace std {
   using std::source_location;
 } // namespace std

diff  --git a/libcxx/modules/std/span.cppm b/libcxx/modules/std/span.inc
similarity index 94%
rename from libcxx/modules/std/span.cppm
rename to libcxx/modules/std/span.inc
index 98bd270a3974c9..184591c6b170d9 100644
--- a/libcxx/modules/std/span.cppm
+++ b/libcxx/modules/std/span.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <span>
-
-export module std:span;
 export namespace std {
   // constants
   using std::dynamic_extent;

diff  --git a/libcxx/modules/std/spanstream.cppm b/libcxx/modules/std/spanstream.inc
similarity index 84%
rename from libcxx/modules/std/spanstream.cppm
rename to libcxx/modules/std/spanstream.inc
index 6106add97b3a97..e6383a185e0798 100644
--- a/libcxx/modules/std/spanstream.cppm
+++ b/libcxx/modules/std/spanstream.inc
@@ -7,13 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#if __has_include(<spanstream>)
-#  error "include this header unconditionally and uncomment the exported symbols"
-#  include <spanstream>
-#endif
-
-export module std:spanstream;
 export namespace std {
 #if 0
   using std::basic_spanbuf;

diff  --git a/libcxx/modules/std/sstream.cppm b/libcxx/modules/std/sstream.inc
similarity index 89%
rename from libcxx/modules/std/sstream.cppm
rename to libcxx/modules/std/sstream.inc
index 1dacb6386f662c..2218001290d0f0 100644
--- a/libcxx/modules/std/sstream.cppm
+++ b/libcxx/modules/std/sstream.inc
@@ -7,15 +7,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <__config>
-#ifndef _LIBCPP_HAS_NO_LOCALIZATION
-#  include <sstream>
-#endif
-
-export module std:sstream;
-#ifndef _LIBCPP_HAS_NO_LOCALIZATION
 export namespace std {
+#ifndef _LIBCPP_HAS_NO_LOCALIZATION
   using std::basic_stringbuf;
 
   using std::swap;
@@ -45,5 +38,5 @@ export namespace std {
 #  ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
   using std::wstringstream;
 #  endif
-} // namespace std
 #endif // _LIBCPP_HAS_NO_LOCALIZATION
+} // namespace std

diff  --git a/libcxx/modules/std/stack.cppm b/libcxx/modules/std/stack.inc
similarity index 93%
rename from libcxx/modules/std/stack.cppm
rename to libcxx/modules/std/stack.inc
index 91cec2dd189dc1..3f736ff0e84108 100644
--- a/libcxx/modules/std/stack.cppm
+++ b/libcxx/modules/std/stack.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <stack>
-
-export module std:stack;
 export namespace std {
   // [stack], class template stack
   using std::stack;

diff  --git a/libcxx/modules/std/stacktrace.cppm b/libcxx/modules/std/stacktrace.inc
similarity index 83%
rename from libcxx/modules/std/stacktrace.cppm
rename to libcxx/modules/std/stacktrace.inc
index c7db9c2d4e99f8..c1184087c0df40 100644
--- a/libcxx/modules/std/stacktrace.cppm
+++ b/libcxx/modules/std/stacktrace.inc
@@ -7,13 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#if __has_include(<stacktrace>)
-#  error "include this header unconditionally and uncomment the exported symbols"
-#  include <stacktrace>
-#endif
-
-export module std:stacktrace;
 export namespace std {
 #if 0
   // [stacktrace.entry], class stacktrace_­entry

diff  --git a/libcxx/modules/std/stdexcept.cppm b/libcxx/modules/std/stdexcept.inc
similarity index 91%
rename from libcxx/modules/std/stdexcept.cppm
rename to libcxx/modules/std/stdexcept.inc
index 686b8a7832457a..15d37bafdba95c 100644
--- a/libcxx/modules/std/stdexcept.cppm
+++ b/libcxx/modules/std/stdexcept.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <stdexcept>
-
-export module std:stdexcept;
 export namespace std {
   using std::domain_error;
   using std::invalid_argument;

diff  --git a/libcxx/modules/std/stdfloat.cppm b/libcxx/modules/std/stdfloat.inc
similarity index 84%
rename from libcxx/modules/std/stdfloat.cppm
rename to libcxx/modules/std/stdfloat.inc
index 740fd475e3afb2..7e7201a854154c 100644
--- a/libcxx/modules/std/stdfloat.cppm
+++ b/libcxx/modules/std/stdfloat.inc
@@ -7,13 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#if __has_include(<stdfloat>)
-#  error "include this header unconditionally"
-#  include <stdfloat>
-#endif
-
-export module std:stdfloat;
 export namespace std {
 #if defined(__STDCPP_FLOAT16_T__)
   using std::float16_t;

diff  --git a/libcxx/modules/std/stop_token.cppm b/libcxx/modules/std/stop_token.inc
similarity index 92%
rename from libcxx/modules/std/stop_token.cppm
rename to libcxx/modules/std/stop_token.inc
index 80a575580fec98..80b53e96b7149f 100644
--- a/libcxx/modules/std/stop_token.cppm
+++ b/libcxx/modules/std/stop_token.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <stop_token>
-
-export module std:stop_token;
 export namespace std {
   // [stoptoken], class stop_­token
   using std::stop_token;

diff  --git a/libcxx/modules/std/streambuf.cppm b/libcxx/modules/std/streambuf.inc
similarity index 83%
rename from libcxx/modules/std/streambuf.cppm
rename to libcxx/modules/std/streambuf.inc
index 7b3d989fca81e1..32914cfe53687d 100644
--- a/libcxx/modules/std/streambuf.cppm
+++ b/libcxx/modules/std/streambuf.inc
@@ -7,19 +7,12 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <__config>
-#ifndef _LIBCPP_HAS_NO_LOCALIZATION
-#  include <streambuf>
-#endif
-
-export module std:streambuf;
-#ifndef _LIBCPP_HAS_NO_LOCALIZATION
 export namespace std {
+#ifndef _LIBCPP_HAS_NO_LOCALIZATION
   using std::basic_streambuf;
   using std::streambuf;
 #  ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
   using std::wstreambuf;
 #  endif
-} // namespace std
 #endif // _LIBCPP_HAS_NO_LOCALIZATION
+} // namespace std

diff  --git a/libcxx/modules/std/string.cppm b/libcxx/modules/std/string.inc
similarity index 97%
rename from libcxx/modules/std/string.cppm
rename to libcxx/modules/std/string.inc
index 9696d58c7a1648..76b384c8b54be4 100644
--- a/libcxx/modules/std/string.cppm
+++ b/libcxx/modules/std/string.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <string>
-
-export module std:string;
 export namespace std {
   // [char.traits], character traits
   using std::char_traits;

diff  --git a/libcxx/modules/std/string_view.cppm b/libcxx/modules/std/string_view.inc
similarity index 95%
rename from libcxx/modules/std/string_view.cppm
rename to libcxx/modules/std/string_view.inc
index ac90006797dacd..1fa63a77395358 100644
--- a/libcxx/modules/std/string_view.cppm
+++ b/libcxx/modules/std/string_view.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <string_view>
-
-export module std:string_view;
 export namespace std {
   // [string.view.template], class template basic_string_view
   using std::basic_string_view;

diff  --git a/libcxx/modules/std/strstream.cppm b/libcxx/modules/std/strstream.inc
similarity index 82%
rename from libcxx/modules/std/strstream.cppm
rename to libcxx/modules/std/strstream.inc
index 0f4fe7f6d0043f..a33c514f150274 100644
--- a/libcxx/modules/std/strstream.cppm
+++ b/libcxx/modules/std/strstream.inc
@@ -7,18 +7,11 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <__config>
-#ifndef _LIBCPP_HAS_NO_LOCALIZATION
-#  include <strstream>
-#endif
-
-export module std:strstream;
-#ifndef _LIBCPP_HAS_NO_LOCALIZATION
 export namespace std {
+#ifndef _LIBCPP_HAS_NO_LOCALIZATION
   using std::istrstream;
   using std::ostrstream;
   using std::strstream;
   using std::strstreambuf;
-} // namespace std
 #endif // _LIBCPP_HAS_NO_LOCALIZATION
+} // namespace std

diff  --git a/libcxx/modules/std/syncstream.cppm b/libcxx/modules/std/syncstream.inc
similarity index 80%
rename from libcxx/modules/std/syncstream.cppm
rename to libcxx/modules/std/syncstream.inc
index 310f279d58bf57..df9b679e38842b 100644
--- a/libcxx/modules/std/syncstream.cppm
+++ b/libcxx/modules/std/syncstream.inc
@@ -7,13 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#if __has_include(<syncstream>)
-#  error "include this header unconditionally and uncomment the exported symbols"
-#  include <syncstream>
-#endif
-
-export module std:syncstream;
 export namespace std {
 #if 0
   using std::basic_syncbuf;

diff  --git a/libcxx/modules/std/system_error.cppm b/libcxx/modules/std/system_error.inc
similarity index 94%
rename from libcxx/modules/std/system_error.cppm
rename to libcxx/modules/std/system_error.inc
index 71c1dca6fedac5..cf553a5ee4a181 100644
--- a/libcxx/modules/std/system_error.cppm
+++ b/libcxx/modules/std/system_error.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <system_error>
-
-export module std:system_error;
 export namespace std {
   using std::error_category;
   using std::generic_category;

diff  --git a/libcxx/modules/std/text_encoding.cppm b/libcxx/modules/std/text_encoding.cppm
deleted file mode 100644
index dcbaa734a68564..00000000000000
--- a/libcxx/modules/std/text_encoding.cppm
+++ /dev/null
@@ -1,26 +0,0 @@
-// -*- C++ -*-
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-module;
-#if __has_include(<text_encoding>)
-#  error "include this header unconditionally and uncomment the exported symbols"
-#  include <text_encoding>
-#endif
-
-export module std:text_encoding;
-export namespace std {
-#if 0
-#  if _LIBCPP_STD_VER >= 23
-  using std::text_encoding;
-
-  // hash support
-  using std::hash;
-#  endif // _LIBCPP_STD_VER >= 23
-#endif
-} // namespace std

diff  --git a/libcxx/modules/std/text_encoding.inc b/libcxx/modules/std/text_encoding.inc
new file mode 100644
index 00000000000000..6d5e3f1d68c605
--- /dev/null
+++ b/libcxx/modules/std/text_encoding.inc
@@ -0,0 +1,19 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+export namespace std {
+#if 0
+#  if _LIBCPP_STD_VER >= 23
+  using std::text_encoding;
+
+  // hash support
+  using std::hash;
+#  endif // _LIBCPP_STD_VER >= 23
+#endif
+} // namespace std

diff  --git a/libcxx/modules/std/thread.cppm b/libcxx/modules/std/thread.inc
similarity index 94%
rename from libcxx/modules/std/thread.cppm
rename to libcxx/modules/std/thread.inc
index 1bfffa29a1b5c7..aa4a7dbd202a20 100644
--- a/libcxx/modules/std/thread.cppm
+++ b/libcxx/modules/std/thread.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <thread>
-
-export module std:thread;
 export namespace std {
   // [thread.thread.class], class thread
   using std::thread;

diff  --git a/libcxx/modules/std/tuple.cppm b/libcxx/modules/std/tuple.inc
similarity index 96%
rename from libcxx/modules/std/tuple.cppm
rename to libcxx/modules/std/tuple.inc
index 6c7dc5c7bf009f..9a8fb72cb63ea5 100644
--- a/libcxx/modules/std/tuple.cppm
+++ b/libcxx/modules/std/tuple.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <tuple>
-
-export module std:tuple;
 export namespace std {
   // [tuple.tuple], class template tuple
   using std::tuple;

diff  --git a/libcxx/modules/std/type_traits.cppm b/libcxx/modules/std/type_traits.inc
similarity index 99%
rename from libcxx/modules/std/type_traits.cppm
rename to libcxx/modules/std/type_traits.inc
index aca0aa95a4a3f3..f0ec4cb6c71a30 100644
--- a/libcxx/modules/std/type_traits.cppm
+++ b/libcxx/modules/std/type_traits.inc
@@ -7,9 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <type_traits>
-export module std:type_traits;
 export namespace std {
   // [meta.help], helper class
   using std::integral_constant;

diff  --git a/libcxx/modules/std/typeindex.cppm b/libcxx/modules/std/typeindex.inc
similarity index 88%
rename from libcxx/modules/std/typeindex.cppm
rename to libcxx/modules/std/typeindex.inc
index 386ed6bf4b430c..0fdcd8fb440f13 100644
--- a/libcxx/modules/std/typeindex.cppm
+++ b/libcxx/modules/std/typeindex.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <typeindex>
-
-export module std:typeindex;
 export namespace std {
   using std::hash;
   using std::type_index;

diff  --git a/libcxx/modules/std/typeinfo.cppm b/libcxx/modules/std/typeinfo.inc
similarity index 89%
rename from libcxx/modules/std/typeinfo.cppm
rename to libcxx/modules/std/typeinfo.inc
index 39e6257a1fd48a..ee1273baf48965 100644
--- a/libcxx/modules/std/typeinfo.cppm
+++ b/libcxx/modules/std/typeinfo.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <typeinfo>
-
-export module std:typeinfo;
 export namespace std {
   using std::bad_cast;
   using std::bad_typeid;

diff  --git a/libcxx/modules/std/unordered_map.cppm b/libcxx/modules/std/unordered_map.inc
similarity index 92%
rename from libcxx/modules/std/unordered_map.cppm
rename to libcxx/modules/std/unordered_map.inc
index 4469e0dc630193..eff62f30540a77 100644
--- a/libcxx/modules/std/unordered_map.cppm
+++ b/libcxx/modules/std/unordered_map.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <unordered_map>
-
-export module std:unordered_map;
 export namespace std {
   // [unord.map], class template unordered_­map
   using std::unordered_map;

diff  --git a/libcxx/modules/std/unordered_set.cppm b/libcxx/modules/std/unordered_set.inc
similarity index 92%
rename from libcxx/modules/std/unordered_set.cppm
rename to libcxx/modules/std/unordered_set.inc
index f3329fc57837bc..c214e3420434b6 100644
--- a/libcxx/modules/std/unordered_set.cppm
+++ b/libcxx/modules/std/unordered_set.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <unordered_set>
-
-export module std:unordered_set;
 export namespace std {
   // [unord.set], class template unordered_­set
   using std::unordered_set;

diff  --git a/libcxx/modules/std/utility.cppm b/libcxx/modules/std/utility.inc
similarity index 97%
rename from libcxx/modules/std/utility.cppm
rename to libcxx/modules/std/utility.inc
index b6aa2aea503022..c8e4dc396cff3e 100644
--- a/libcxx/modules/std/utility.cppm
+++ b/libcxx/modules/std/utility.inc
@@ -7,9 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <utility>
-export module std:utility;
 export namespace std {
   // [utility.swap], swap
   using std::swap;

diff  --git a/libcxx/modules/std/valarray.cppm b/libcxx/modules/std/valarray.inc
similarity index 96%
rename from libcxx/modules/std/valarray.cppm
rename to libcxx/modules/std/valarray.inc
index 39c5e95712bbe2..1cdf7f14060fb2 100644
--- a/libcxx/modules/std/valarray.cppm
+++ b/libcxx/modules/std/valarray.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <valarray>
-
-export module std:valarray;
 export namespace std {
   using std::gslice;
   using std::gslice_array;

diff  --git a/libcxx/modules/std/variant.cppm b/libcxx/modules/std/variant.inc
similarity index 96%
rename from libcxx/modules/std/variant.cppm
rename to libcxx/modules/std/variant.inc
index 7e96ba3b8076d3..6fcecddbedaf50 100644
--- a/libcxx/modules/std/variant.cppm
+++ b/libcxx/modules/std/variant.inc
@@ -7,10 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <variant>
-
-export module std:variant;
 export namespace std {
   // [variant.variant], class template variant
   using std::variant;

diff  --git a/libcxx/modules/std/vector.cppm b/libcxx/modules/std/vector.inc
similarity index 91%
rename from libcxx/modules/std/vector.cppm
rename to libcxx/modules/std/vector.inc
index 9ebe2d4ed84379..a9ce764fc81da8 100644
--- a/libcxx/modules/std/vector.cppm
+++ b/libcxx/modules/std/vector.inc
@@ -7,11 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-module;
-#include <functional>
-#include <vector>
-
-export module std:vector;
 export namespace std {
   // [vector], class template vector
   using std::vector;

diff  --git a/libcxx/modules/std/version.cppm b/libcxx/modules/std/version.cppm
deleted file mode 100644
index c2e8f09fec5b67..00000000000000
--- a/libcxx/modules/std/version.cppm
+++ /dev/null
@@ -1,16 +0,0 @@
-// -*- C++ -*-
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-module;
-#include <version>
-
-export module std:version;
-export namespace std {
-  // This module exports nothing.
-} // namespace std

diff  --git a/libcxx/modules/std/version.inc b/libcxx/modules/std/version.inc
new file mode 100644
index 00000000000000..2ab8eb970e7a5e
--- /dev/null
+++ b/libcxx/modules/std/version.inc
@@ -0,0 +1,12 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+export namespace std {
+  // This module exports nothing.
+} // namespace std

diff  --git a/libcxx/test/libcxx/module_std.gen.py b/libcxx/test/libcxx/module_std.gen.py
index 534da5398c6e0e..17f671e9192169 100644
--- a/libcxx/test/libcxx/module_std.gen.py
+++ b/libcxx/test/libcxx/module_std.gen.py
@@ -119,6 +119,9 @@
 # same definition.
 ExtraHeader["functional"] = "v1/__compare/compare_three_way.h$"
 
+# newline needs to be escaped for the module partition output.
+nl = '\\\\n'
+
 # Create empty file with all parts.
 print(
     f"""\
@@ -140,14 +143,30 @@
     if header.endswith(".h"):  # Skip C compatibility headers
         continue
 
+    # Generate a module partition for the header module includes. This
+    # makes it possible to verify that all headers export all their
+    # named declarations.
+    #
+    # TODO MODULES This needs to take the header restrictions into account.
+    print(
+        f"// RUN{BLOCKLIT}: echo -e \""
+        f"module;{nl}"
+        f"#include <{header}>{nl}"
+        f"{nl}"
+        f"// Use __libcpp_module_<HEADER> to ensure that modules {nl}"
+        f"// are not named as keywords or reserved names.{nl}"
+        f"export module std:__libcpp_module_{header};{nl}"
+        f'#include \\"%{{module}}/std/{header}.inc\\"{nl}'
+        f"\" > %t.{header}.cppm")
+
     # Dump the information as found in the module's cppm file.
     print(
-        f"// RUN{BLOCKLIT}: %{{clang-tidy}} %{{module}}/std/{header}.cppm "
+        f"// RUN{BLOCKLIT}: %{{clang-tidy}} %t.{header}.cppm "
         "  --checks='-*,libcpp-header-exportable-declarations' "
         "  -config='{CheckOptions: [ "
         "    {"
         "      key: libcpp-header-exportable-declarations.Filename, "
-        f"     value: {header}.cppm"
+        f"     value: {header}.inc"
         "    }, {"
         "      key: libcpp-header-exportable-declarations.FileType, "
         "      value: ModulePartition"

diff  --git a/libcxx/test/tools/clang_tidy_checks/header_exportable_declarations.cpp b/libcxx/test/tools/clang_tidy_checks/header_exportable_declarations.cpp
index f691f4ee6392ab..281d1ec6dfdb0e 100644
--- a/libcxx/test/tools/clang_tidy_checks/header_exportable_declarations.cpp
+++ b/libcxx/test/tools/clang_tidy_checks/header_exportable_declarations.cpp
@@ -222,14 +222,8 @@ void header_exportable_declarations::check(const clang::ast_matchers::MatchFinde
     if (is_reserved_name(name))
       return;
 
-    // For modules (std, std.compat) only take the declarations exported from the partitions.
-    // Making sure no declatations of headers are compared.
-    if (file_type_ == FileType::Module)
-      if (clang::Module* M = decl->getOwningModule(); M && M->Kind != clang::Module::ModulePartitionInterface)
-        return;
-
-    // For module partitions only take exported declarations.
-    if (file_type_ == FileType::ModulePartition)
+    // For modules only take the declarations exported.
+    if (file_type_ == FileType::ModulePartition || file_type_ == FileType::Module)
       if (decl->getModuleOwnershipKind() != clang::Decl::ModuleOwnershipKind::VisibleWhenImported)
         return;
 


        


More information about the libcxx-commits mailing list