[libcxx-commits] [libcxx] 1eb74f7 - [libc++] Remove the chrono include from algorithm

Ian Anderson via libcxx-commits libcxx-commits at lists.llvm.org
Sat Apr 22 11:31:24 PDT 2023


Author: Ian Anderson
Date: 2023-04-22T11:31:19-07:00
New Revision: 1eb74f7e83ffb3f9d00e5987cead3b12e00bbe82

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

LOG: [libc++] Remove the chrono include from algorithm

algorithm's include of chrono causes include cycles:

```
algorithm -> chrono -> __chrono/convert_to_tm.h -> __chrono/statically_widen.h -> __format/concepts.h -> __format/format_parse_context.h -> string_view -> algorithm

algorithm -> chrono -> __chrono/convert_to_tm.h -> __chrono/statically_widen.h -> __format/concepts.h -> __format/format_parse_context.h -> string_view -> functional -> __functional/boyer_moore_searcher.h -> array -> algorithm

algorithm -> chrono -> __chrono/convert_to_tm.h -> __chrono/statically_widen.h -> __format/concepts.h -> __format/format_parse_context.h -> string_view -> functional -> __functional/boyer_moore_searcher.h -> unordered_map -> algorithm

algorithm -> chrono -> __chrono/convert_to_tm.h -> __chrono/statically_widen.h -> __format/concepts.h -> __format/format_parse_context.h -> string_view -> functional -> __functional/boyer_moore_searcher.h -> vector -> algorithm
```

This is a problem for clang modules after the std mega module is broken up, because it becomes a module cycle which is a hard error.

All of the includes in the `__chrono` and `__format` headers are being used and so can't be removed. algorithm's include of chrono is already removed in C++20, whereas the array, string_view, unordered_map, vector includes of algorithm aren't removed until C++23 (and it's 4x the includes that would need removing). Unconditionally remove the chrono include from algorithm in all versions, so that the module breakup can happen (the module has to apply to all C++ versions).

Reviewed By: Mordante, #libc

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

Added: 
    

Modified: 
    libcxx/docs/ReleaseNotes.rst
    libcxx/include/algorithm
    libcxx/test/libcxx/transitive_includes/cxx03.csv
    libcxx/test/libcxx/transitive_includes/cxx11.csv
    libcxx/test/libcxx/transitive_includes/cxx14.csv
    libcxx/test/libcxx/transitive_includes/cxx17.csv

Removed: 
    


################################################################################
diff  --git a/libcxx/docs/ReleaseNotes.rst b/libcxx/docs/ReleaseNotes.rst
index 4f79793ccdd9..fdbfdacfd36c 100644
--- a/libcxx/docs/ReleaseNotes.rst
+++ b/libcxx/docs/ReleaseNotes.rst
@@ -67,6 +67,8 @@ Deprecations and Removals
   - C++2b: ``atomic``, ``bit``, ``cstdint``, ``cstdlib``, ``cstring``, ``initializer_list``, ``limits``, ``new``,
            ``stdexcept``, ``system_error``, ``type_traits``, ``typeinfo``
 
+- ``<algorithm>`` no longer includes ``<chrono>`` in any C++ version (it was prevously included in C++17 and earlier).
+
 - The headers ``<experimental/algorithm>`` and ``<experimental/functional>`` have been removed, since all the contents
   have been implemented in namespace ``std`` for at least two releases.
 

diff  --git a/libcxx/include/algorithm b/libcxx/include/algorithm
index 7e251ebd833d..f5dcffa0a3f8 100644
--- a/libcxx/include/algorithm
+++ b/libcxx/include/algorithm
@@ -1917,10 +1917,6 @@ template <class BidirectionalIterator, class Compare>
 #  pragma GCC system_header
 #endif
 
-#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 17
-#  include <chrono>
-#endif
-
 #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
 #  include <atomic>
 #  include <bit>

diff  --git a/libcxx/test/libcxx/transitive_includes/cxx03.csv b/libcxx/test/libcxx/transitive_includes/cxx03.csv
index 2ad5c5b363d2..ef7efa519d4b 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx03.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx03.csv
@@ -1,6 +1,5 @@
 algorithm atomic
 algorithm bit
-algorithm chrono
 algorithm climits
 algorithm concepts
 algorithm cstddef
@@ -854,6 +853,7 @@ thread chrono
 thread compare
 thread cstddef
 thread cstdint
+thread cstdlib
 thread cstring
 thread ctime
 thread functional

diff  --git a/libcxx/test/libcxx/transitive_includes/cxx11.csv b/libcxx/test/libcxx/transitive_includes/cxx11.csv
index b69d828405fa..3eecead0ae1b 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx11.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx11.csv
@@ -1,6 +1,5 @@
 algorithm atomic
 algorithm bit
-algorithm chrono
 algorithm climits
 algorithm concepts
 algorithm cstddef
@@ -855,6 +854,7 @@ thread chrono
 thread compare
 thread cstddef
 thread cstdint
+thread cstdlib
 thread cstring
 thread ctime
 thread functional

diff  --git a/libcxx/test/libcxx/transitive_includes/cxx14.csv b/libcxx/test/libcxx/transitive_includes/cxx14.csv
index 6d029a7b685e..ec68a819d0ae 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx14.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx14.csv
@@ -1,6 +1,5 @@
 algorithm atomic
 algorithm bit
-algorithm chrono
 algorithm climits
 algorithm concepts
 algorithm cstddef
@@ -857,6 +856,7 @@ thread chrono
 thread compare
 thread cstddef
 thread cstdint
+thread cstdlib
 thread cstring
 thread ctime
 thread functional

diff  --git a/libcxx/test/libcxx/transitive_includes/cxx17.csv b/libcxx/test/libcxx/transitive_includes/cxx17.csv
index 6d029a7b685e..ec68a819d0ae 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx17.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx17.csv
@@ -1,6 +1,5 @@
 algorithm atomic
 algorithm bit
-algorithm chrono
 algorithm climits
 algorithm concepts
 algorithm cstddef
@@ -857,6 +856,7 @@ thread chrono
 thread compare
 thread cstddef
 thread cstdint
+thread cstdlib
 thread cstring
 thread ctime
 thread functional


        


More information about the libcxx-commits mailing list