[libcxx-commits] [PATCH] D156907: [libc++][modules] Removes the module partitions.

Mark de Wever via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Wed Aug 2 10:45:36 PDT 2023


Mordante created this revision.
Herald added a subscriber: arphaman.
Herald added a project: All.
Mordante published this revision for review.
Mordante added reviewers: ldionne, ChuanqiXu, aaronmondal.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156907

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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156907.546486.patch
Type: text/x-patch
Size: 74442 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20230802/1c85a4cb/attachment-0001.bin>


More information about the libcxx-commits mailing list