[libc++] Take advantage of -fexperimental-library in libc++
authorLouis Dionne <ldionne.2@gmail.com>
Wed, 20 Jul 2022 14:42:04 +0000 (10:42 -0400)
committerLouis Dionne <ldionne.2@gmail.com>
Fri, 22 Jul 2022 12:33:39 +0000 (08:33 -0400)
When -fexperimental-library is passed, libc++ will now pick up the
appropriate __has_feature flag defined by Clang to enable the
experimental library features.

As a fly-by, also update the documentation for the various TSes.

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

libcxx/docs/DesignDocs/ExperimentalFeatures.rst
libcxx/docs/ReleaseNotes.rst
libcxx/docs/Status/Cxx20.rst
libcxx/docs/UsingLibcxx.rst
libcxx/include/__config
libcxx/test/libcxx/experimental/fexperimental-library.compile.pass.cpp [new file with mode: 0644]
libcxx/utils/libcxx/test/params.py

index 2241496..defe0e4 100644 (file)
@@ -143,7 +143,8 @@ Most (but not all) of the features of the LFTS were accepted into C++17.
 `FileSystem TS <https://wg21.link/N4100>`__
 -------------------------------------------
 The FileSystem TS was accepted (in totality) for C++17.
-The FileSystem TS implementation was shipped in namespace ``std`` in LLVM 7.0, and will be removed in LLVM 11.0 (due to the lack of deprecation warnings before LLVM 9.0).
+The FileSystem TS implementation was shipped in namespace ``std`` in LLVM 7.0, and was
+removed in LLVM 11.0 (due to the lack of deprecation warnings before LLVM 9.0).
 
 Parallelism TS `V1 <https://wg21.link/N4507>`__ and `V2 <https://wg21.link/N4706>`__
 ------------------------------------------------------------------------------------
@@ -152,8 +153,10 @@ We have not yet shipped an implementation of the Parallelism TS.
 
 `Coroutines TS <https://wg21.link/N4680>`__
 -------------------------------------------
-The Coroutines TS is not yet part of a shipping standard.
-We are shipping (as of v5.0) an implementation of the Coroutines TS in namespace ``std::experimental``.
+The Coroutines TS was accepted for C++20.
+An implementation of the Coroutines TS was shipped in LLVM 5.0 in namespace ``std::experimental``,
+and C++20 Coroutines shipped in LLVM 14.0. The implementation of the Coroutines TS in ``std::experimental``
+will be removed in LLVM 16.0.
 
 `Networking TS <https://wg21.link/N4656>`__
 -------------------------------------------
@@ -162,13 +165,15 @@ We have not yet shipped an implementation of the Networking TS.
 
 `Ranges TS <https://wg21.link/N4685>`__
 ---------------------------------------
-The Ranges TS is not yet part of a shipping standard.
-We have not yet shipped an implementation of the Ranges TS.
+The Ranges TS was accepted for C++20.
+We will not ship an implementation of the Ranges TS, however we are actively working on
+the implementation of C++20 Ranges.
 
 `Concepts TS <https://wg21.link/N4641>`__
 -----------------------------------------
-The Concepts TS is not yet part of a shipping standard, but it has been adopted into the C++20 working draft.
-We have not yet shipped an implementation of the Concepts TS.
+The Concepts TS was accepted for C++20.
+We will not ship an implementation of the Concepts TS, however we are shipping an
+implementation of C++20 Concepts.
 
 `Concurrency TS <https://wg21.link/P0159>`__
 --------------------------------------------
index 2708ff2..96e98fd 100644 (file)
@@ -89,6 +89,13 @@ Improvements and New Features
   should include assertions or not by default. For details, see
   :ref:`the documentation <assertions-mode>` about this new feature.
 
+- Clang now implements the ``-fexperimental-library`` flag. This flag can be used to
+  enable experimental library features such as TSes and other in-progress work like
+  ``<ranges>`` and ``<format>``. Using this flag makes it unnecessary to manually link
+  against ``libc++experimental.a`` -- just use ``-fexperimental-library`` and the
+  compiler will do what's needed to make experimental features work. However, be
+  aware that experimental features are not stable!
+
 - The implementation of the function ``std::to_chars`` for integral types using
   base 10 has moved from the dylib to the header. This means the function no
   longer has a minimum deployment target.
index 742d91a..43d29c5 100644 (file)
@@ -42,7 +42,7 @@ Paper Status
 
    .. [#note-P0600] P0600: The missing bits in P0600 are in |sect|\ [mem.res.class] and |sect|\ [mem.poly.allocator.class].
    .. [#note-P0645] P0645: The paper is implemented but still marked as an incomplete feature
-      (the feature-test macro is not set and the libary is only available when built with ``-D_LIBCPP_ENABLE_EXPERIMENTAL``).
+      (the feature-test macro is not set and the libary is only available when built with ``-fexperimental-library``).
       Not yet implemented LWG-issues will cause API and ABI breakage.
    .. [#note-P0966] P0966: It was previously erroneously marked as complete in version 8.0. See `bug 45368 <https://llvm.org/PR45368>`__.
    .. [#note-P0619] P0619: Only sections D.8, D.9, D.10 and D.13 are implemented. Sections D.4, D.7, D.11, D.12, and D.14 remain undone.
index 47cbe2d..aa58120 100644 (file)
@@ -41,12 +41,10 @@ Libc++ provides implementations of some experimental features. Experimental feat
 are either Technical Specifications (TSes) or official features that were voted to
 the Standard but whose implementation is not complete or stable yet in libc++. Those
 are disabled by default because they are neither API nor ABI stable. However, the
-``_LIBCPP_ENABLE_EXPERIMENTAL`` macro can be defined to turn those features on. Note
-that you will also need to link to the appropriate ``libc++experimental.a`` static
-archive.
+``-fexperimental-library`` compiler flag can be defined to turn those features on.
 
 .. warning::
-  Experimental libraries are Experimental.
+  Experimental libraries are experimental.
     * The contents of the ``<experimental/...>`` headers and the associated static
       library will not remain compatible between versions.
     * No guarantees of API or ABI stability are provided.
@@ -54,6 +52,12 @@ archive.
       the experimental feature is removed two releases after the non-experimental
       version has shipped. The full policy is explained :ref:`here <experimental features>`.
 
+.. note::
+  On compilers that do not support the ``-fexperimental-library`` flag, users can
+  define the ``_LIBCPP_ENABLE_EXPERIMENTAL`` macro and manually link against the
+  appropriate static library (usually shipped as ``libc++experimental.a``) to get
+  access to experimental library features.
+
 
 Using libc++ when it is not the system default
 ==============================================
index edb5b98..8c2f761 100644 (file)
@@ -243,6 +243,12 @@ If there are users of this configuration we are happy to provide support.
 #    define _LIBCPP_ABI_VCRUNTIME
 #  endif
 
+#  if __has_feature(experimental_library)
+#    ifndef _LIBCPP_ENABLE_EXPERIMENTAL
+#      define _LIBCPP_ENABLE_EXPERIMENTAL
+#    endif
+#  endif
+
 // Incomplete features get their own specific disabling flags. This makes it
 // easier to grep for target specific flags once the feature is complete.
 #  if !defined(_LIBCPP_ENABLE_EXPERIMENTAL) && !defined(_LIBCPP_BUILDING_LIBRARY)
diff --git a/libcxx/test/libcxx/experimental/fexperimental-library.compile.pass.cpp b/libcxx/test/libcxx/experimental/fexperimental-library.compile.pass.cpp
new file mode 100644 (file)
index 0000000..c04dd5a
--- /dev/null
@@ -0,0 +1,35 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// This test ensures that passing `-fexperimental-library` results in experimental
+// library features being enabled.
+
+// GCC does not support the -fexperimental-library flag
+// UNSUPPORTED: gcc
+
+// Clang does not support the -fexperimental-library flag before LLVM 15.0
+// UNSUPPORTED: clang-13, clang-14
+
+// AppleClang does not support the -fexperimental-library flag yet
+// UNSUPPORTED: apple-clang-13
+
+// Clang on AIX currently pretends that it is Clang 15, even though it is not (as of writing
+// this, LLVM 15 hasn't even been branched yet).
+// UNSUPPORTED: clang-15 && buildhost=aix
+
+// ADDITIONAL_COMPILE_FLAGS: -fexperimental-library
+
+#include <version>
+
+#ifdef _LIBCPP_HAS_NO_INCOMPLETE_FORMAT
+#   error "-fexperimental-library should enable <format>"
+#endif
+
+#ifdef _LIBCPP_HAS_NO_INCOMPLETE_RANGES
+#   error "-fexperimental-library should enable <ranges>"
+#endif
index c3823f8..3f223ac 100644 (file)
@@ -166,9 +166,6 @@ DEFAULT_PARAMETERS = [
               # to make it link against the static libc++experimental.lib.
               # We can't check for the feature 'msvc' in available_features
               # as those features are added after processing parameters.
-              #
-              # TODO: Switch to using the appropriate experimental compiler flag once
-              #       all compilers we support implement that flag.
               AddFeature('c++experimental'),
               PrependLinkFlag(lambda cfg: '-llibc++experimental' if _isMSVC(cfg) else '-lc++experimental'),
               AddCompileFlag('-D_LIBCPP_ENABLE_EXPERIMENTAL'),