[libcxx-commits] [libcxx] deb3b55 - [libc++] Take advantage of -fexperimental-library in libc++

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Fri Jul 22 05:33:57 PDT 2022


Author: Louis Dionne
Date: 2022-07-22T08:33:39-04:00
New Revision: deb3b5552f04656dee27067b2cc68c906012cfe4

URL: https://github.com/llvm/llvm-project/commit/deb3b5552f04656dee27067b2cc68c906012cfe4
DIFF: https://github.com/llvm/llvm-project/commit/deb3b5552f04656dee27067b2cc68c906012cfe4.diff

LOG: [libc++] Take advantage of -fexperimental-library in libc++

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

Added: 
    libcxx/test/libcxx/experimental/fexperimental-library.compile.pass.cpp

Modified: 
    libcxx/docs/DesignDocs/ExperimentalFeatures.rst
    libcxx/docs/ReleaseNotes.rst
    libcxx/docs/Status/Cxx20.rst
    libcxx/docs/UsingLibcxx.rst
    libcxx/include/__config
    libcxx/utils/libcxx/test/params.py

Removed: 
    


################################################################################
diff  --git a/libcxx/docs/DesignDocs/ExperimentalFeatures.rst b/libcxx/docs/DesignDocs/ExperimentalFeatures.rst
index 2241496d5943f..defe0e4e2428f 100644
--- a/libcxx/docs/DesignDocs/ExperimentalFeatures.rst
+++ b/libcxx/docs/DesignDocs/ExperimentalFeatures.rst
@@ -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>`__
 --------------------------------------------

diff  --git a/libcxx/docs/ReleaseNotes.rst b/libcxx/docs/ReleaseNotes.rst
index 2708ff271fb73..96e98fd5c9ab3 100644
--- a/libcxx/docs/ReleaseNotes.rst
+++ b/libcxx/docs/ReleaseNotes.rst
@@ -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.

diff  --git a/libcxx/docs/Status/Cxx20.rst b/libcxx/docs/Status/Cxx20.rst
index 742d91aea8580..43d29c5c9d886 100644
--- a/libcxx/docs/Status/Cxx20.rst
+++ b/libcxx/docs/Status/Cxx20.rst
@@ -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.

diff  --git a/libcxx/docs/UsingLibcxx.rst b/libcxx/docs/UsingLibcxx.rst
index 47cbe2d514eec..aa581207cf079 100644
--- a/libcxx/docs/UsingLibcxx.rst
+++ b/libcxx/docs/UsingLibcxx.rst
@@ -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
 ==============================================

diff  --git a/libcxx/include/__config b/libcxx/include/__config
index edb5b983fe66a..8c2f7614af537 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -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
index 0000000000000..c04dd5abb1d30
--- /dev/null
+++ b/libcxx/test/libcxx/experimental/fexperimental-library.compile.pass.cpp
@@ -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

diff  --git a/libcxx/utils/libcxx/test/params.py b/libcxx/utils/libcxx/test/params.py
index c3823f805f2cf..3f223ac17f3bb 100644
--- a/libcxx/utils/libcxx/test/params.py
+++ b/libcxx/utils/libcxx/test/params.py
@@ -166,9 +166,6 @@ def getStdFlag(cfg, std):
               # 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'),


        


More information about the libcxx-commits mailing list