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

207 lines
5.5 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 {
// [pointer.traits], pointer traits
using std::pointer_traits;
// [pointer.conversion], pointer conversion
using std::to_address;
// [ptr.align], pointer alignment
using std::align;
using std::assume_aligned;
// [obj.lifetime], explicit lifetime management
// using std::start_lifetime_as;
// using std::start_lifetime_as_array;
// [allocator.tag], allocator argument tag
using std::allocator_arg;
using std::allocator_arg_t;
// [allocator.uses], uses_allocator
using std::uses_allocator;
// [allocator.uses.trait], uses_allocator
using std::uses_allocator_v;
// [allocator.uses.construction], uses-allocator construction
using std::uses_allocator_construction_args;
using std::make_obj_using_allocator;
using std::uninitialized_construct_using_allocator;
// [allocator.traits], allocator traits
using std::allocator_traits;
using std::allocation_result;
using std::allocate_at_least;
// [default.allocator], the default allocator
using std::allocator;
using std::operator==;
// [specialized.addressof], addressof
using std::addressof;
// [specialized.algorithms], specialized algorithms
// [special.mem.concepts], special memory concepts
using std::uninitialized_default_construct;
using std::uninitialized_default_construct_n;
namespace ranges {
using std::ranges::uninitialized_default_construct;
using std::ranges::uninitialized_default_construct_n;
} // namespace ranges
using std::uninitialized_value_construct;
using std::uninitialized_value_construct_n;
namespace ranges {
using std::ranges::uninitialized_value_construct;
using std::ranges::uninitialized_value_construct_n;
} // namespace ranges
using std::uninitialized_copy;
using std::uninitialized_copy_n;
namespace ranges {
using std::ranges::uninitialized_copy;
using std::ranges::uninitialized_copy_result;
using std::ranges::uninitialized_copy_n;
using std::ranges::uninitialized_copy_n_result;
} // namespace ranges
using std::uninitialized_move;
using std::uninitialized_move_n;
namespace ranges {
using std::ranges::uninitialized_move;
using std::ranges::uninitialized_move_result;
using std::ranges::uninitialized_move_n;
using std::ranges::uninitialized_move_n_result;
} // namespace ranges
using std::uninitialized_fill;
using std::uninitialized_fill_n;
namespace ranges {
using std::ranges::uninitialized_fill;
using std::ranges::uninitialized_fill_n;
} // namespace ranges
// [specialized.construct], construct_at
using std::construct_at;
namespace ranges {
using std::ranges::construct_at;
}
// [specialized.destroy], destroy
using std::destroy;
using std::destroy_at;
using std::destroy_n;
namespace ranges {
using std::ranges::destroy;
using std::ranges::destroy_at;
using std::ranges::destroy_n;
} // namespace ranges
// [unique.ptr], class template unique_ptr
using std::default_delete;
using std::unique_ptr;
using std::make_unique;
using std::make_unique_for_overwrite;
using std::operator<;
using std::operator>;
using std::operator<=;
using std::operator>=;
using std::operator<=>;
using std::operator<<;
// [util.smartptr.weak.bad], class bad_weak_ptr
using std::bad_weak_ptr;
// [util.smartptr.shared], class template shared_ptr
using std::shared_ptr;
// [util.smartptr.shared.create], shared_ptr creation
using std::allocate_shared;
using std::allocate_shared_for_overwrite;
using std::make_shared;
using std::make_shared_for_overwrite;
// [util.smartptr.shared.spec], shared_ptr specialized algorithms
using std::swap;
// [util.smartptr.shared.cast], shared_ptr casts
using std::const_pointer_cast;
using std::dynamic_pointer_cast;
using std::reinterpret_pointer_cast;
using std::static_pointer_cast;
using std::get_deleter;
// [util.smartptr.shared.io], shared_ptr I/O
// [util.smartptr.weak], class template weak_ptr
using std::weak_ptr;
// [util.smartptr.weak.spec], weak_ptr specialized algorithms
// [util.smartptr.ownerless], class template owner_less
using std::owner_less;
// [util.smartptr.enab], class template enable_shared_from_this
using std::enable_shared_from_this;
// [util.smartptr.hash], hash support
using std::hash;
// [util.smartptr.atomic], atomic smart pointers
// using std::atomic;
// [out.ptr.t], class template out_ptr_t
// using std::out_ptr_t;
// [out.ptr], function template out_ptr
// using std::out_ptr;
// [inout.ptr.t], class template inout_ptr_t
// using std::inout_ptr_t;
// [inout.ptr], function template inout_ptr
// using std::inout_ptr;
// [depr.util.smartptr.shared.atomic]
using std::atomic_is_lock_free;
using std::atomic_load;
using std::atomic_load_explicit;
using std::atomic_store;
using std::atomic_store_explicit;
using std::atomic_exchange;
using std::atomic_exchange_explicit;
using std::atomic_compare_exchange_strong;
using std::atomic_compare_exchange_strong_explicit;
using std::atomic_compare_exchange_weak;
using std::atomic_compare_exchange_weak_explicit;
} // namespace std