Skip to content

Commit

Permalink
[libc++][C++20 modules] Enabling in C++20.
Browse files Browse the repository at this point in the history
The vendors of the MSVC STL, libstdc++ and libc++ have agreed [1] to
make the C++23 modules std and std.compat available in C++20. This
provides the std module; libc++ has not implemented the std.compat
module yet.

[1] microsoft/STL#3945

Depends on D158357

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D158358
  • Loading branch information
mordante authored and avillega committed Sep 11, 2023
1 parent cd96d9b commit 4ed50c3
Show file tree
Hide file tree
Showing 20 changed files with 68 additions and 9 deletions.
3 changes: 3 additions & 0 deletions libcxx/docs/Modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,13 @@ What works
* ``LIBCXX_ENABLE_RANDOM_DEVICE``
* ``LIBCXX_ENABLE_UNICODE``

* A C++20 based extension

Some of the current limitations
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

* There is no official build system support, libc++ has experimental CMake support
* Requires CMake 3.26 for C++20 support
* Requires CMake 3.26 for C++23 support
* Requires CMake 3.27 for C++26 support
* Requires Ninja 1.11
Expand Down
6 changes: 6 additions & 0 deletions libcxx/docs/UsingLibcxx.rst
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,12 @@ in their code base.
In C++26 formatting pointers gained a type ``P`` and allows to use
zero-padding. These options have been retroactively applied to C++20.

Extensions to the C++23 modules ``std`` and ``std.compat``
----------------------------------------------------------

Like other major implementations, libc++ provides C++23 modules ``std`` and
``std.compat`` in C++20 as an extension"

.. _turning-off-asan:

Turning off ASan annotation in containers
Expand Down
8 changes: 5 additions & 3 deletions libcxx/modules/std/algorithm.inc
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,11 @@ export namespace std {
}

namespace ranges {
#if _LIBCPP_STD_VER >= 23
// [alg.starts.with], starts with
using std::ranges::starts_with;

#if 0
# if 0
// [alg.ends.with], ends with
using std::ranges::ends_with;

Expand All @@ -167,8 +168,9 @@ export namespace std {
using std::ranges::fold_left_with_iter;
using std::ranges::fold_left_first_with_iter;
using std::ranges::fold_left_first_with_iter;
#endif
} // namespace ranges
# endif
#endif // _LIBCPP_STD_VER >= 23
} // namespace ranges

// [alg.modifying.operations], mutating sequence operations
// [alg.copy], copy
Expand Down
2 changes: 2 additions & 0 deletions libcxx/modules/std/bit.inc
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ export namespace std {
// [bit.cast], bit_cast
using std::bit_cast;

#if _LIBCPP_STD_VER >= 23
// [bit.byteswap], byteswap
using std::byteswap;
#endif

// [bit.pow.two], integral powers of 2
using std::bit_ceil;
Expand Down
2 changes: 2 additions & 0 deletions libcxx/modules/std/expected.inc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//

export namespace std {
#if _LIBCPP_STD_VER >= 23
// [expected.unexpected], class template unexpected
using std::unexpected;

Expand All @@ -20,4 +21,5 @@ export namespace std {

// [expected.expected], class template expected
using std::expected;
#endif // _LIBCPP_STD_VER >= 23
} // namespace std
4 changes: 4 additions & 0 deletions libcxx/modules/std/format.inc
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ export namespace std {
// [format.formatter], formatter
using std::formatter;

#if _LIBCPP_STD_VER >= 23
// [format.formattable], concept formattable
using std::formattable;
#endif

// [format.parse.ctx], class template basic_format_parse_context
using std::basic_format_parse_context;
Expand All @@ -52,13 +54,15 @@ export namespace std {
using std::wformat_parse_context;
#endif

#if _LIBCPP_STD_VER >= 23
// [format.range], formatting of ranges
// [format.range.fmtkind], variable template format_kind
using std::format_kind;
using std::range_format;

// [format.range.formatter], class template range_formatter
using std::range_formatter;
#endif // _LIBCPP_STD_VER >= 23

// [format.arg], class template basic_format_arg
using std::basic_format_arg;
Expand Down
2 changes: 2 additions & 0 deletions libcxx/modules/std/functional.inc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
export namespace std {
// [func.invoke], invoke
using std::invoke;
#if _LIBCPP_STD_VER >= 23
using std::invoke_r;
#endif

// [refwrap], reference_wrapper
using std::reference_wrapper;
Expand Down
2 changes: 2 additions & 0 deletions libcxx/modules/std/mdspan.inc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//

export namespace std {
#if _LIBCPP_STD_VER >= 23
// [mdspan.extents], class template extents
using std::extents;

Expand All @@ -24,4 +25,5 @@ export namespace std {

// [mdspan.mdspan], class template mdspan
using std::mdspan;
#endif // _LIBCPP_STD_VER >= 23
} // namespace std
2 changes: 2 additions & 0 deletions libcxx/modules/std/memory.inc
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ export namespace std {
// [allocator.traits], allocator traits
using std::allocator_traits;

#if _LIBCPP_STD_VER >= 23
using std::allocation_result;

using std::allocate_at_least;
#endif

// [default.allocator], the default allocator
using std::allocator;
Expand Down
6 changes: 4 additions & 2 deletions libcxx/modules/std/print.inc
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
//===----------------------------------------------------------------------===//

export namespace std {
#if _LIBCPP_STD_VER >= 23
// [print.fun], print functions
using std::print;
using std::println;

using std::vprint_nonunicode;
#ifndef _LIBCPP_HAS_NO_UNICODE
# ifndef _LIBCPP_HAS_NO_UNICODE
using std::vprint_unicode;
#endif // _LIBCPP_HAS_NO_UNICODE
# endif // _LIBCPP_HAS_NO_UNICODE
#endif // _LIBCPP_STD_VER >= 23
} // namespace std
10 changes: 10 additions & 0 deletions libcxx/modules/std/ranges.inc
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,10 @@ export namespace std {

using std::ranges::borrowed_subrange_t;

#if _LIBCPP_STD_VER >= 23
// [range.utility.conv], range conversions
using std::ranges::to;
#endif

// [range.empty], empty view
using std::ranges::empty_view;
Expand All @@ -114,12 +116,14 @@ export namespace std {
using std::ranges::views::iota;
} // namespace views

#if _LIBCPP_STD_VER >= 23
// [range.repeat], repeat view
using std::ranges::repeat_view;

namespace views {
using std::ranges::views::repeat;
} // namespace views
#endif // _LIBCPP_STD_VER >= 23

#ifndef _LIBCPP_HAS_NO_LOCALIZATION
// [range.istream], istream view
Expand Down Expand Up @@ -149,12 +153,14 @@ export namespace std {
// [range.owning.view], owning view
using std::ranges::owning_view;

#if _LIBCPP_STD_VER >= 23
// [range.as.rvalue], as rvalue view
using std::ranges::as_rvalue_view;

namespace views {
using std::ranges::views::as_rvalue;
} // namespace views
#endif // _LIBCPP_STD_VER >= 23

// [range.filter], filter view
using std::ranges::filter_view;
Expand Down Expand Up @@ -259,12 +265,14 @@ export namespace std {
using std::ranges::views::values;
} // namespace views

#if _LIBCPP_STD_VER >= 23
// [range.zip], zip view
using std::ranges::zip_view;

namespace views {
using std::ranges::views::zip;
} // namespace views
#endif // _LIBCPP_STD_VER >= 23

#if 0
// [range.zip.transform], zip transform view
Expand Down Expand Up @@ -329,6 +337,8 @@ export namespace std {
using std::tuple_element;
using std::tuple_size;

#if _LIBCPP_STD_VER >= 23
using std::from_range;
using std::from_range_t;
#endif // _LIBCPP_STD_VER >= 23
} // namespace std
2 changes: 1 addition & 1 deletion libcxx/modules/std/string.inc
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export namespace std {
using std::hash;

// TODO MODULES is this a bug?
#if 1
#if _LIBCPP_STD_VER >= 23
using std::operator""s;
#else
inline namespace literals {
Expand Down
2 changes: 2 additions & 0 deletions libcxx/modules/std/thread.inc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ export namespace std {
using std::operator<<;
# endif // _LIBCPP_HAS_NO_LOCALIZATION

# if _LIBCPP_STD_VER >= 23
using std::formatter;
# endif

using std::hash;
#endif // _LIBCPP_HAS_NO_THREADS
Expand Down
2 changes: 2 additions & 0 deletions libcxx/modules/std/tuple.inc
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ export namespace std {

// [tuple.like], concept tuple-like

#if _LIBCPP_STD_VER >= 23
// [tuple.common.ref], common_reference related specializations
using std::basic_common_reference;
using std::common_type;
#endif

// [tuple.creation], tuple creation functions
using std::ignore;
Expand Down
4 changes: 4 additions & 0 deletions libcxx/modules/std/type_traits.inc
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ export namespace std {
using std::is_volatile;

using std::is_bounded_array;
#if _LIBCPP_STD_VER >= 23
using std::is_scoped_enum;
#endif
using std::is_signed;
using std::is_unbounded_array;
using std::is_unsigned;
Expand Down Expand Up @@ -255,7 +257,9 @@ export namespace std {
using std::is_nothrow_swappable_v;
using std::is_nothrow_swappable_with_v;
using std::is_polymorphic_v;
#if _LIBCPP_STD_VER >= 23
using std::is_scoped_enum_v;
#endif
using std::is_signed_v;
using std::is_standard_layout_v;
using std::is_swappable_v;
Expand Down
6 changes: 6 additions & 0 deletions libcxx/modules/std/utility.inc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ export namespace std {

// [forward], forward/move
using std::forward;
#if _LIBCPP_STD_VER >= 23
using std::forward_like;
#endif
using std::move;
using std::move_if_noexcept;

Expand All @@ -37,11 +39,13 @@ export namespace std {

using std::in_range;

#if _LIBCPP_STD_VER >= 23
// [utility.underlying], to_underlying
using std::to_underlying;

// [utility.unreachable], unreachable
using std::unreachable;
#endif // _LIBCPP_STD_VER >= 23

// [intseq], compile-time integer sequences
using std::index_sequence;
Expand All @@ -55,8 +59,10 @@ export namespace std {
// [pairs], class template pair
using std::pair;

#if _LIBCPP_STD_VER >= 23
using std::basic_common_reference;
using std::common_type;
#endif
// [pairs.spec], pair specialized algorithms
using std::operator==;
using std::operator<=>;
Expand Down
2 changes: 2 additions & 0 deletions libcxx/modules/std/vector.inc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export namespace std {
// hash support
using std::hash;

#if _LIBCPP_STD_VER >= 23
// [vector.bool.fmt], formatter specialization for vector<bool>
using std::formatter;
#endif
} // namespace std
2 changes: 1 addition & 1 deletion libcxx/test/libcxx/module_std.gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
print(
f"""\
//--- module_std.sh.cpp
// UNSUPPORTED{BLOCKLIT}: c++03, c++11, c++14, c++17, c++20
// UNSUPPORTED{BLOCKLIT}: c++03, c++11, c++14, c++17
// UNSUPPORTED{BLOCKLIT}: libcpp-has-no-std-modules
// UNSUPPORTED{BLOCKLIT}: modules-build
Expand Down
2 changes: 2 additions & 0 deletions libcxx/test/lit.local.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ if std == "cxx26":
std = "26"
elif std == "cxx23":
std = "23"
elif std == "cxx20":
std = "20"
else:
std = ""

Expand Down
8 changes: 6 additions & 2 deletions libcxx/utils/ci/buildkite-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,13 @@ steps:
- "**/test-results.xml"
- "**/*.abilist"
env:
CC: "clang-${LLVM_HEAD_VERSION}"
CXX: "clang++-${LLVM_HEAD_VERSION}"
# Note: Modules require and absolute path for clang-scan-deps
# https://github.com/llvm/llvm-project/issues/61006
CC: "/usr/lib/llvm-${LLVM_HEAD_VERSION}/bin/clang"
CXX: "/usr/lib/llvm-${LLVM_HEAD_VERSION}/bin/clang++"
CMAKE: "/opt/bin/cmake"
ENABLE_CLANG_TIDY: "On"
ENABLE_STD_MODULES: "On"
agents:
queue: "libcxx-builders"
os: "linux"
Expand Down

0 comments on commit 4ed50c3

Please sign in to comment.