Mark de Wever 4d4c70c91c [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
2023-08-09 19:39:08 +02:00

118 lines
3.1 KiB
C++

// -*- 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 {
#ifndef _LIBCPP_HAS_NO_LOCALIZATION
// [re.const], regex constants
namespace regex_constants {
using std::regex_constants::error_type;
using std::regex_constants::match_flag_type;
using std::regex_constants::syntax_option_type;
// regex_constants is a bitmask type.
// [bitmask.types] specified operators
using std::regex_constants::operator&;
using std::regex_constants::operator&=;
using std::regex_constants::operator^;
using std::regex_constants::operator^=;
using std::regex_constants::operator|;
using std::regex_constants::operator|=;
using std::regex_constants::operator~;
} // namespace regex_constants
// [re.badexp], class regex_error
using std::regex_error;
// [re.traits], class template regex_traits
using std::regex_traits;
// [re.regex], class template basic_regex
using std::basic_regex;
using std::regex;
# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
using std::wregex;
# endif
// [re.regex.swap], basic_regex swap
using std::swap;
// [re.submatch], class template sub_match
using std::sub_match;
using std::csub_match;
using std::ssub_match;
# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
using std::wcsub_match;
using std::wssub_match;
# endif
// [re.submatch.op], sub_match non-member operators
using std::operator==;
using std::operator<=>;
using std::operator<<;
// [re.results], class template match_results
using std::match_results;
using std::cmatch;
using std::smatch;
# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
using std::wcmatch;
using std::wsmatch;
# endif
// match_results comparisons
// [re.results.swap], match_results swap
// [re.alg.match], function template regex_match
using std::regex_match;
// [re.alg.search], function template regex_search
using std::regex_search;
// [re.alg.replace], function template regex_replace
using std::regex_replace;
// [re.regiter], class template regex_iterator
using std::regex_iterator;
using std::cregex_iterator;
using std::sregex_iterator;
# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
using std::wcregex_iterator;
using std::wsregex_iterator;
# endif
// [re.tokiter], class template regex_token_iterator
using std::regex_token_iterator;
using std::cregex_token_iterator;
using std::sregex_token_iterator;
# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
using std::wcregex_token_iterator;
using std::wsregex_token_iterator;
# endif
namespace pmr {
using std::pmr::match_results;
using std::pmr::cmatch;
using std::pmr::smatch;
# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
using std::pmr::wcmatch;
using std::pmr::wsmatch;
# endif
} // namespace pmr
#endif // _LIBCPP_HAS_NO_LOCALIZATION
} // namespace std