Commit Graph

295 Commits

Author SHA1 Message Date
Nikolas Klauser
627e6efa5b Revert "[libc++][PSTL] Implement std::transform"
This reverts commit cbd9e54547.

The wrong patch was landed.
2023-05-15 06:56:40 -07:00
Nikolas Klauser
cbd9e54547 [libc++][PSTL] Implement std::transform
Reviewed By: ldionne, #libc

Spies: libcxx-commits

Differential Revision: https://reviews.llvm.org/D149615
2023-05-15 06:48:43 -07:00
Nikolas Klauser
e7e3711885 [libc++][PSTL] Make the PSTL available by default under -fexperimental-library
This removes the need for a custom libc++ build to have a basic set of PSTL algorithms.

Reviewed By: ldionne, #libc

Spies: miyuki, libcxx-commits, arichardson

Differential Revision: https://reviews.llvm.org/D149624
2023-05-05 13:53:17 -07:00
Nikolas Klauser
ade9c3bdca [libc++][PSTL] Implement std::fill{,_n}
Reviewed By: ldionne, #libc

Spies: libcxx-commits

Differential Revision: https://reviews.llvm.org/D149540
2023-05-01 14:03:40 -07:00
Nikolas Klauser
824391693c [libc++][PSTL] Implement std::find{,_if,_if_not}
Reviewed By: ldionne, #libc

Spies: libcxx-commits

Differential Revision: https://reviews.llvm.org/D149539
2023-05-01 09:04:29 -07:00
Nikolas Klauser
68ee014b15 [libc++][PSTL] Implement std::for_each{, _n}
Reviewed By: ldionne, #libc

Spies: libcxx-commits

Differential Revision: https://reviews.llvm.org/D149381
2023-04-30 13:27:20 -07:00
Nikolas Klauser
8af259e8d9 [libc++][PSTL] Implement std::{any, all, none}_of
Reviewed By: ldionne, #libc

Spies: arichardson, libcxx-commits, miyuki

Differential Revision: https://reviews.llvm.org/D143161
2023-04-29 20:41:42 -07:00
Ian Anderson
1eb74f7e83 [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
2023-04-22 11:31:19 -07:00
Nikolas Klauser
7d98590b3a [libc++][PSTL] Remove current integration
We decided to go a different route. To make the switch easier, rip out the old integration first and build on a clean base.

Reviewed By: ldionne, #libc, #libc_abi

Spies: arichardson, libcxx-commits

Differential Revision: https://reviews.llvm.org/D148480
2023-04-21 05:31:07 +02:00
Nikolas Klauser
75196f8e72 [libc++] Remove <cstdlib> includes
We changed the `abort` calls when trying to throw exceptions in `-fno-exceptions` mode to `__verbose_abort` calls, which removes the dependency in most files.

Reviewed By: ldionne, #libc

Spies: dim, emaste, mikhail.ramalho, smeenai, libcxx-commits

Differential Revision: https://reviews.llvm.org/D146076
2023-04-09 02:52:33 +02:00
Mark de Wever
de6827b530 [libc++] Improves clang-format settings.
Add a new test based .clang-format file which inherits from the generic
one. This moves some test specific formatting rules to the test
directory.

The main benefit is that headers are sorted, which makes it more likely
to catch these errors before creating a review instead of spotting the
error in the CI clang-tidy step.

Reviewed By: ldionne, philnik, #libc

Differential Revision: https://reviews.llvm.org/D144755
2023-02-27 19:24:06 +01:00
Nikolas Klauser
40a20ae6ab [libc++] Granularize <bit> includes
Reviewed By: ldionne, #libc

Spies: libcxx-commits

Differential Revision: https://reviews.llvm.org/D141228
2023-02-17 11:36:19 +01:00
Nikolas Klauser
e698c59504 [libc++] Granularize <type_traits> includes in <algorithm>
Reviewed By: Mordante, #libc

Spies: libcxx-commits, wenlei

Differential Revision: https://reviews.llvm.org/D140673
2023-02-13 13:21:25 +01:00
Adrian Vogelsgesang
2a06757a20 [libc++][spaceship] Implement lexicographical_compare_three_way
The implementation makes use of the freedom added by LWG 3410. We have
two variants of this algorithm:
* a fast path for random access iterators: This fast path computes the
  maximum number of loop iterations up-front and does not compare the
  iterators against their limits on every loop iteration.
* A basic implementation for all other iterators: This implementation
  compares the iterators against their limits in every loop iteration.
  However, it still takes advantage of the freedom added by LWG 3410 to
  avoid unnecessary additional iterator comparisons, as originally
  specified by P1614R2.

https://godbolt.org/z/7xbMEen5e shows the benefit of the fast path:
The hot loop generated of `lexicographical_compare_three_way3` is
more tight than for `lexicographical_compare_three_way1`. The added
benchmark illustrates how this leads to a 30% - 50% performance
improvement on integer vectors.

Implements part of P1614R2 "The Mothership has Landed"

Fixes LWG 3410 and LWG 3350

Differential Revision: https://reviews.llvm.org/D131395
2023-02-12 14:51:08 -08:00
varconst
5629d492df Reapply "[libc++][ranges]Refactor copy{,_backward} and move{,_backward}"
This reverts commit a6e1080b87.

Fix the conditions when the `memmove` optimization can be applied and refactor them out into a reusable type trait, fix and significantly expand the tests.

Differential Revision: https://reviews.llvm.org/D139235
2023-01-13 16:57:13 -08:00
Nikolas Klauser
86aac87fe4 [libc++] Granularize <bit> and remove <__bits>
Reviewed By: Mordante, #libc

Spies: libcxx-commits

Differential Revision: https://reviews.llvm.org/D141225
2023-01-08 17:01:21 +01:00
Nikolas Klauser
89b356f05a [libc++] Granularize <concept> includes
Reviewed By: ldionne, #libc

Spies: libcxx-commits

Differential Revision: https://reviews.llvm.org/D137283
2022-11-05 20:59:29 +01:00
Vitaly Buka
a6e1080b87 Revert "[libc++][ranges]Refactor copy{,_backward} and move{,_backward}"
Breaks msan, asan

https://lab.llvm.org/buildbot/#/builders/5/builds/27904

This reverts commit 005916de58.
2022-10-02 16:23:35 -07:00
Konstantin Varlamov
005916de58 [libc++][ranges]Refactor copy{,_backward} and move{,_backward}
Instead of using `reverse_iterator`, share the optimization between the 4 algorithms. The key observation here that `memmove` applies to both `copy` and `move` identically, and to their `_backward` versions very similarly. All algorithms now follow the same pattern along the lines of:
```
if constexpr (can_memmove<InIter, OutIter>) {
  memmove(first, last, out);
} else {
  naive_implementation(first, last, out);
}
```
A follow-up will delete `unconstrained_reverse_iterator`.

This patch removes duplication and divergence between `std::copy`, `std::move` and `std::move_backward`. It also improves testing:
- the test for whether the optimization is used only applied to `std::copy` and, more importantly, was essentially a no-op because it would still pass if the optimization was not used;
- there were no tests to make sure the optimization is not used when the effect would be visible.

Differential Revision: https://reviews.llvm.org/D130695
2022-10-01 17:35:12 -07:00
Nikolas Klauser
473a160506 [libc++][NFC] Fix some standard-mandated includes comments
Reviewed By: ldionne, #libc

Spies: libcxx-commits

Differential Revision: https://reviews.llvm.org/D134447
2022-09-27 21:11:53 +02:00
Mark de Wever
ddb6c2b301 [libc++] Rewrites graph_header_deps.py.
The new version is a lot simpler and has less option which were not
used. This uses the CSV files as generated by D133127 as input data.

The current Python script has more features but uses a simple "grep"
making the output less accurate:
- Conditionally included header are always included. This is an issue
  since part of our includes are unneeded transitive includes. Based on
  the language version they may be omitted. The script however always
  includes them.
- Includes in comments are processed as-if they are includes. This is an
  issue when comments explain how certain data is generated; of course
  there are digraphs which the script omits.

This implementation uses Clang's --trace-includes to generate the includes
per header. This means the input of the generation script always has the
real list of includes.

Libc++ is moving from large monolithic Standard headers to more fine
grained headers. For example, algorithm includes every header in
`__algorithm`. Adding all these detail headers in the graph makes the
output unusable. Instead it only shows the Standard headers. The
transitive includes of the detail headers are parsed and "attributed" to
the Standard header including them. This gives an accurate include graph
without the unneeded clutter. Note that this graph is still big.

This changes fixes the cyclic dependency issue with the previous version
of the tool so the markers and its documentation is removed.

Since the input has no cycles the CI test is removed.

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D134188
2022-09-25 15:06:21 +02:00
Nikolas Klauser
d5e26775d0 [libc++] Granularize the rest of memory
Reviewed By: ldionne, #libc

Spies: vitalybuka, paulkirth, libcxx-commits, mgorny

Differential Revision: https://reviews.llvm.org/D132790
2022-09-05 12:36:41 +02:00
Mark de Wever
e31c2a1b1a [NFC][libc++] Moves transitive includes location.
As discussed in D132284 they will be moved to the end.

Reviewed By: #libc, Mordante

Differential Revision: https://reviews.llvm.org/D133212
2022-09-03 10:06:16 +02:00
Vitaly Buka
bc8fd9c633 Revert "[libc++] Granularize the rest of memory"
Breaks buildbots.

This reverts commit 30adaa730c.
2022-09-02 19:42:49 -07:00
Nikolas Klauser
30adaa730c [libc++] Granularize the rest of memory
Reviewed By: ldionne, #libc

Spies: libcxx-commits, mgorny

Differential Revision: https://reviews.llvm.org/D132790
2022-09-02 21:42:41 +02:00
Mark de Wever
8ff2d6af69 [libc++] Reduces the number of transitive includes.
This defines a new policy for removal of transitive includes.
The goal of the policy it to make it relatively easy to remove
headers when needed, but avoid breaking developers using and
vendors shipping libc++.

The method used is to guard transitive includes based on the
C++ language version. For the upcoming C++23 we can remove
headers when we want, but for other language versions we try
to keep it to a minimum.

In this code the transitive include of `<chrono>` is removed
since D128577 introduces a header cycle between `<format>`
and `<chrono>`. This cycle is indirectly required by the
Standard. Our cycle dependency tool basically is a grep based
tool, so it needs some hints to ignore cycles. With the input
of our transitive include tests we can create a better tool.
However that's out of the scope of this patch.

Note the flag `_LIBCPP_REMOVE_TRANSITIVE_INCLUDES` remains
unchanged. So users can still opt-out of transitives includes
entirely.

Reviewed By: #libc, ldionne, philnik

Differential Revision: https://reviews.llvm.org/D132284
2022-08-31 19:50:03 +02:00
Nikolas Klauser
4038c859e5 [libc++][ranges] Implement ranges::is_permutation
Co-authored-by: Konstantin Varlamov <varconst@apple.com>

Differential Revision: https://reviews.llvm.org/D127194
2022-08-04 10:54:37 -07:00
Igor Zhukov
1915c1c01e [libc++][NFC] Remove rebase artifact
I found it in this commit: a203acb9dd

Reviewed By: Mordante

Differential Revision: https://reviews.llvm.org/D131163
2022-08-04 22:53:32 +07:00
Nikolas Klauser
a203acb9dd [libc++][ranges] Implement ranges::clamp
Differential Revision: https://reviews.llvm.org/D126193
2022-08-04 02:45:32 -07:00
Konstantin Varlamov
36c746ca2d [libc++][ranges] Implement ranges::rotate.
Also fix `ranges::stable_sort` and `ranges::inplace_merge` to support
proxy iterators now that their internal implementations can correctly
dispatch `rotate`.

Differential Revision: https://reviews.llvm.org/D130758
2022-08-03 16:04:24 -07:00
Nikolas Klauser
68264b6494 [libc++][ranges] Implement ranges::{prev, next}_permutation.
Co-authored-by: Konstantin Varlamov <varconst@apple.com>

Differential Revision: https://reviews.llvm.org/D129859
2022-08-02 22:46:15 -07:00
Konstantin Varlamov
6bdb642234 [libc++][ranges] Implement ranges::sample.
Differential Revision: https://reviews.llvm.org/D130865
2022-08-02 22:34:23 -07:00
Nikolas Klauser
93172c1c2b [libc++][ranges] Implement ranges::replace_copy{,_if}.
Co-authored-by: Konstantin Varlamov <varconst@apple.com>

Differential Revision: https://reviews.llvm.org/D129806
2022-08-02 22:32:01 -07:00
Nikolas Klauser
760d2b462c [libc++][ranges] Implement ranges::remove_copy{, _if}.
Co-authored-by: Hui Xie <hui.xie1990@gmail.com>

Differential Revision: https://reviews.llvm.org/D130599
2022-08-02 22:19:13 -07:00
Konstantin Varlamov
db7d795978 [libc++][ranges] Implement std::ranges::partial_sort_copy.
Differential Revision: https://reviews.llvm.org/D130532
2022-07-30 02:42:18 -07:00
Hui Xie
72f57e3a30 [libc++][ranges] implement std::ranges::unique{_copy}
implement `std::ranges::unique` and `std::ranges::unique_copy`

Differential Revision: https://reviews.llvm.org/D130404
2022-07-29 08:28:17 +01:00
Hui Xie
8a61749f76 [libc++][ranges] implement std::ranges::inplace_merge
Differential Revision: https://reviews.llvm.org/D130627
2022-07-28 08:37:48 +01:00
Konstantin Varlamov
d406c6493e [libc++][ranges] Implement ranges::is_heap{,_until}.
Differential Revision: https://reviews.llvm.org/D130547
2022-07-26 16:11:24 -07:00
Konstantin Varlamov
ead7302bbb [libc++][ranges] Implement ranges::generate{,_n}.
Differential Revision: https://reviews.llvm.org/D130552
2022-07-26 15:50:32 -07:00
Konstantin Varlamov
14cf74d65d [libc++][ranges] Implement ranges::shuffle.
Differential Revision: https://reviews.llvm.org/D130321
2022-07-22 09:59:13 -07:00
Hui Xie
c559964d85 [libc++][ranges] implement std::ranges::includes
implement `std::ranges::includes` and delegate to `std::includes`

Differential Revision: https://reviews.llvm.org/D130116
2022-07-22 10:27:48 +01:00
Hui Xie
0f6364b8a1 [libc++][ranges] implement std::ranges::equal_range
implement `std::ranges::equal_range` which delegates to
`std::equal_range`

Differential Revision: https://reviews.llvm.org/D129796
2022-07-22 10:24:08 +01:00
Konstantin Varlamov
065202f3ca [libc++][ranges] Implement std::ranges::partition_{point,copy}.
Reviewed By: #libc, huixie90, ldionne

Differential Revision: https://reviews.llvm.org/D130070
2022-07-20 11:39:07 -07:00
varconst
5dd19ada57 [libc++][ranges] Implement ranges::partial_sort.
Differential Revision: https://reviews.llvm.org/D128744
2022-07-19 20:10:34 -07:00
Konstantin Varlamov
8ed702b83f [libc++][ranges] Implement ranges::{,stable_}partition.
Differential Revision: https://reviews.llvm.org/D129624
2022-07-18 21:06:17 -07:00
Hui Xie
3151b95dad [libc++][ranges] implement std::ranges::set_union
[libc++][ranges] implement `std::ranges::set_union`

Differential Revision: https://reviews.llvm.org/D129657
2022-07-14 21:05:30 +01:00
Hui Xie
a5c0638dec [libc++][ranges] implement std::ranges::set_symmetric_difference
[libc++][ranges] implement `std::ranges::set_symmetric_difference`

Differential Revision: https://reviews.llvm.org/D129520
2022-07-13 21:24:32 +01:00
Nikolas Klauser
101d1e9b3c [libc++] Implement ranges::find_end, ranges::search{, _n}
Reviewed By: var-const, #libc, huixie90

Spies: thakis, h-vetinari, huixie90, libcxx-commits, mgorny

Differential Revision: https://reviews.llvm.org/D124079
2022-07-13 20:30:55 +02:00
Nikolas Klauser
1f04759316 Revert "[libc++] Implement ranges::find_end, ranges::search{, _n}"
This reverts commit 76a7651850.
2022-07-13 13:41:25 +02:00
Nikolas Klauser
76a7651850 [libc++] Implement ranges::find_end, ranges::search{, _n}
Reviewed By: var-const, #libc, huixie90

Spies: h-vetinari, huixie90, libcxx-commits, mgorny

Differential Revision: https://reviews.llvm.org/D124079
2022-07-13 13:11:26 +02:00