Commit Graph

153 Commits

Author SHA1 Message Date
Louis Dionne b8cb1dc9ea [libc++] Make <ranges> non-experimental
When we ship LLVM 16, <ranges> won't be considered experimental anymore.
We might as well do this sooner rather than later.

Differential Revision: https://reviews.llvm.org/D132151
2022-08-18 16:59:58 -04:00
Nikolas Klauser 7ae66e5e95 [libc++] Granularize the rest of type_traits
Reviewed By: ldionne, #libc

Spies: libcxx-commits, mgorny

Differential Revision: https://reviews.llvm.org/D130471
2022-08-14 10:30:48 +02:00
Nikolas Klauser 80c7e93a2a [libc++] Add a bunch of missing _LIBCPP_HIDE_FROM_ABI
Reviewed By: ldionne, Mordante, var-const, huixie90, #libc

Spies: jloser, libcxx-commits, arichardson, miyuki

Differential Revision: https://reviews.llvm.org/D129968
2022-08-13 22:41:22 +02:00
Louis Dionne b1009bbd9e [libc++] Add missing includes of <cstddef> 2022-08-10 11:35:41 -04: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
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 7912b1f8e7 [libc++] Fix reverse_iterator::iterator_concept
Fixes https://github.com/llvm/llvm-project/issues/56504

Reviewed By: ldionne, Mordante, huixie90, #libc

Spies: libcxx-commits, hewillk

Differential Revision: https://reviews.llvm.org/D129794
2022-07-30 10:53:59 +02:00
Nikolas Klauser 20a11cb550 [libc++] Fix algorithms which use reverse_iterator
This adds a C++20-version of `reverse_iterator` which doesn't SFINAE away the operators for use inside the classic STL algorithms. Pre-C++20 `_AlgRevIter` is just an alias for `reverse_iterator`.

Reviewed By: var-const, #libc

Spies: huixie90, libcxx-commits

Differential Revision: https://reviews.llvm.org/D128864
2022-07-25 18:35:20 +02:00
Nikolas Klauser b7aa9c4ac8 [libc++] Granularize some more type_traits
Reviewed By: ldionne, #libc

Spies: libcxx-commits, mgorny

Differential Revision: https://reviews.llvm.org/D128948
2022-07-24 22:22:12 +02:00
Nikolas Klauser 0a92e0728c [libc++] Use __unwrap_iter_impl for both unwrapping and rewrapping
Reviewed By: ldionne, #libc

Spies: arichardson, sstefan1, libcxx-commits

Differential Revision: https://reviews.llvm.org/D129039
2022-07-14 20:01:19 +02: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
Nikolas Klauser 7d426a392f [libc++] Implement ranges::{reverse, rotate}_copy
Reviewed By: var-const, #libc

Spies: huixie90, libcxx-commits, mgorny

Differential Revision: https://reviews.llvm.org/D127211
2022-07-11 21:13:08 +02:00
Nikolas Klauser b48c5010a4 [libc++] Make parameter names consistent and enforce the naming style using readability-identifier-naming
Ensure that parameter names have the style `__lower_case`

Reviewed By: ldionne, #libc

Spies: aheejin, sstefan1, libcxx-commits, miyuki

Differential Revision: https://reviews.llvm.org/D129051
2022-07-08 18:17:47 +02:00
Nikolas Klauser 00927334df [libc++] Use __is_exactly_{input, forward}_iterator
Reviewed By: ldionne, #libc

Spies: libcxx-commits

Differential Revision: https://reviews.llvm.org/D128646
2022-07-05 10:06:27 +02:00
Konstantin Varlamov 79a2b4ba98 [libc++][ranges] Finish LWG issues directly related to the One Ranges Proposal.
- P1252 ("Ranges Design Cleanup") -- deprecate
  `move_iterator::operator->` starting from C++20; add range comparisons
  to the `<functional>` synopsis. This restores
  `move_iterator::operator->` that was incorrectly deleted in D117656;
  it's still defined in the latest draft, see
  http://eel.is/c++draft/depr.move.iter.elem. Note that changes to
  `*_result` types from 6.1 in the paper are no longer relevant now that
  these types are aliases;
- P2106 ("Alternative wording for GB315 and GB316") -- add a few
  `*_result` types to the synopsis in `<algorithm>` (some algorithms are
  not implemented yet and thus some of the proposal still cannot be
  marked as done);

Also mark already done issues as done (or as nothing to do):
- P2091 ("Fixing Issues With Range Access CPOs") was already implemented
  (this patch adds tests for some ill-formed cases);
- LWG 3247 ("`ranges::iter_move` should perform ADL-only lookup of
  `iter_move`") was already implemented;
- LWG 3300 ("Non-array ssize overload is underconstrained") doesn't
  affect the implementation;
- LWG 3335 ("Resolve C++20 NB comments US 273 and GB 274") was already
  implemented;
- LWG 3355 ("The memory algorithms should support move-only input
  iterators introduced by P1207") was already implemented (except for
  testing).

Differential Revision: https://reviews.llvm.org/D126053
2022-06-28 12:00:15 -07:00
Louis Dionne 633d1d0df7 [libc++] Use bounded iterators in std::span when the debug mode is enabled
Previously, we'd use raw pointers when the debug mode was enabled,
which means we wouldn't get out-of-range checking with std::span's
iterators.

This patch introduces a new class called __bounded_iter which can
be used to wrap iterators and make them carry around bounds-related
information. This allows iterators to assert when they are dereferenced
outside of their bounds.

As a fly-by change, this commit removes the _LIBCPP_ABI_SPAN_POINTER_ITERATORS
knob. Indeed, not using a raw pointer as the iterator type is useful to
avoid users depending on properties of raw pointers in their code.

This is an alternative to D127401.

Differential Revision: https://reviews.llvm.org/D127418
2022-06-27 08:34:45 -04:00
Nikolas Klauser fb3477a4da [libc++] Unwrap reverse_iterator<reverse_iterator<Iter>> in __unwrap_iter
Simplify the implementation of `std::copy` and `std::move` by using `__unwrap_iter` and `__rewrap_iter` to unwrap and rewrap `reverse_iterator<reverse_iterator<Iter>>` instead of specializing `__copy_impl` and `__move_impl`.

Reviewed By: ldionne, #libc

Spies: wenlei, libcxx-commits

Differential Revision: https://reviews.llvm.org/D127049
2022-06-17 18:47:18 +02:00
Nikolas Klauser 988682a389 [libc++] Fix std::lower_bound with C++20-hostile iterators
Reviewed By: EricWF, #libc

Spies: sstefan1, libcxx-commits, mgorny

Differential Revision: https://reviews.llvm.org/D127577
2022-06-13 12:19:28 +02:00
Nikolas Klauser 13558334f3 [libc++] Remove uses of __two in type_traits
Reviewed By: ldionne, #libc

Spies: libcxx-commits

Differential Revision: https://reviews.llvm.org/D127483
2022-06-10 19:56:59 +02:00
Louis Dionne f3966eaf86 [libc++] Make the Debug mode a configuration-time only option
The debug mode has been broken pretty much ever since it was shipped
because it was possible to enable the debug mode in user code without
actually enabling it in the dylib, leading to ODR violations that
caused various kinds of failures.

This commit makes the debug mode a knob that is configured when
building the library and which can't be changed afterwards. This is
less flexible for users, however it will actually work as intended
and it will allow us, in the future, to add various kinds of checks
that do not assume the same ABI as the normal library. Furthermore,
this will make the debug mode more robust, which means that vendors
might be more tempted to support it properly, which hasn't been the
case with the current debug mode.

This patch shouldn't break any user code, except folks who are building
against a library that doesn't have the debug mode enabled and who try
to enable the debug mode in their code. Such users will get a compile-time
error explaining that this configuration isn't supported anymore.

In the future, we should further increase the granularity of the debug
mode checks so that we can cherry-pick which checks to enable, like we
do for unspecified behavior randomization.

Differential Revision: https://reviews.llvm.org/D122941
2022-06-07 16:33:53 -04:00
Louis Dionne eebbfbcd50 [libc++][NFC] Add missing includes 2022-06-06 12:58:23 -04:00
Louis Dionne 4eab04f849 [libc++] Remove a bunch of conditionals on _LIBCPP_DEBUG_LEVEL
Instead of providing two different constructors for iterators that
support the debug mode, provide a single constructor but leave the
container parameter unused when the debug mode is not enabled.

This allows simplifying all the call sites to unconditionally pass
the container, which removes a bunch of duplication in the container's
implementation.

Note that this patch does add some complexity to std::span, however
that is only because std::span has the ability to use raw pointers
as iterators instead of __wrap_iter. In retrospect, I believe it was
a mistake to provide that capability, and so it will be removed in a
future patch, along with the complexity added by this patch.

Differential Revision: https://reviews.llvm.org/D126993
2022-06-06 09:54:26 -04:00
Nikolas Klauser 8171586176 [libc++][ranges] Implement ranges::binary_search and ranges::{lower, upper}_bound
Reviewed By: Mordante, var-const, ldionne, #libc

Spies: sstefan1, libcxx-commits, mgorny

Differential Revision: https://reviews.llvm.org/D121964
2022-06-06 13:33:18 +02:00
Nikolas Klauser ef8e918261 [libc++] Forward more often to memmove in copy
In D122982 I accidentally disabled the memmove optimization. This re-enables it and adds more cases where copy forwards to memmove.
Fixes https://github.com/llvm/llvm-project/issues/33687

Reviewed By: var-const, #libc, ldionne

Spies: pkasting, ayzhao, dcheng, xbolva00, libcxx-commits

Differential Revision: https://reviews.llvm.org/D124328
2022-06-03 20:29:18 +02:00
Konstantin Varlamov b06049bc3b [libc++][NFC] Add more tests to `move_{iterator,sentinel}`.
More test coverage for the parts added by the One Ranges Proposal.

Differential Revision: https://reviews.llvm.org/D124906
2022-05-24 19:56:12 -07:00
Nikolas Klauser 06cf0ce90a [libc++] Enable move semantics for vector in C++03
We require move semantics in C++03 anyways, so let's enable them for the containers.

Reviewed By: ldionne, #libc

Spies: libcxx-commits

Differential Revision: https://reviews.llvm.org/D123802
2022-05-19 16:11:56 +02:00
Peter Kasting 5a4f177c94 [libc++] Avoid a Microsoft SAL macro.
Bug: https://github.com/llvm/llvm-project/issues/55195

Reviewed By: #libc, Mordante

Differential Revision: https://reviews.llvm.org/D124695
2022-05-05 20:08:33 +02:00
Brian Tracy 87a55137e2 Fix "the the" typo in documentation and user facing strings
There are many more instances of this pattern, but I chose to limit this change to .rst files (docs), anything in libcxx/include, and string literals. These have the highest chance of being seen by end users.

Reviewed By: #libc, Mordante, martong, ldionne

Differential Revision: https://reviews.llvm.org/D124708
2022-05-05 17:52:08 +02:00
Louis Dionne db6421ec58 [libc++] Post-commit adjustments after rebasing D117656 2022-04-13 09:51:43 -04:00
Arthur O'Dwyer 2fb026ee4d Implement move_sentinel and C++20 move_iterator.
Differential Revision: https://reviews.llvm.org/D117656
2022-04-13 09:51:43 -04:00
Mark de Wever 476047bf8e [libc++] Adds back_insert_iterator::__get_container.
Adds a `__get_container` member as suggested by @Quuxplusone in D110497.

Includes  s/_LIBCPP_INLINE_VISIBILITY/_LIBCPP_HIDE_FROM_ABI/.

Reviewed By: Quuxplusone, #libc, ldionne

Differential Revision: https://reviews.llvm.org/D110573
2022-04-08 17:13:50 +02:00
Konstantin Varlamov 658957c79a [libc++][ranges] Implement changes to reverse_iterator from One Ranges Proposal.
Changes in [P0896](https://wg21.link/p0896):
- add `disable_sized_sentinel_for`;
- add `iter_move` and `iter_swap`;
- add a `requires` clause to the `operator->`;
- add `iterator_concept`;
- check that the `Iterator` template parameter is a bidirectional
  iterator;
- add constraints to all comparison operators;
- change the definitions of `iterator_category`, `value_type`,
  `difference_type` and `reference` (changes to `iterator_category` were
  already implemented).

Also add a few forgotten things to the `reverse_iterator` synopsis
(notably the spaceship operator).

Differential Revision: https://reviews.llvm.org/D120180
2022-03-17 19:58:03 -07:00
Louis Dionne e39095a32e [libc++] Define _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER whenever we enable warnings in the test suite
This should make CI consistent on all the compilers we support. Most of
this patch is working around various warnings emitted by GCC in our code
base, which are now being shown when we compile the tests.

After this patch, the whole test suite should be warning free on all
compilers we support and test, except for a few warnings on GCC that
we silence explicitly until we figure out the proper fix for them.

Differential Revision: https://reviews.llvm.org/D120684
2022-03-15 17:17:54 -04:00
Joe Loser d2baefae68
[libc++] Replace _LIBCPP_HAS_NO_CONCEPTS with _LIBCPP_STD_VER > 17. NFCI.
All supported compilers that support C++20 now support concepts. So, remove
`_LIB_LIBCPP_HAS_NO_CONCEPTS` in favor of `_LIBCPP_STD_VER > 17`. Similarly in
the tests, remove `// UNSUPPORTED: libcpp-no-concepts`.

Differential Revision: https://reviews.llvm.org/D121528
2022-03-13 12:32:06 -04:00
Arthur O'Dwyer 844a9c0ef4 [libc++] Make common_iterator's proxy types into aggregates.
Saves one move in each case, which is basically nothing perf-wise;
this is more about simplifying the code.

Differential Revision: https://reviews.llvm.org/D121130
2022-03-07 15:44:10 -05:00
Arthur O'Dwyer fbcd5236af [libc++] [ranges] Fix `decltype(auto) ranges::iter_move`.
See
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92894#c3
https://reviews.llvm.org/D119589#inline-1151299

Differential Revision: https://reviews.llvm.org/D120417
2022-03-07 13:31:16 -05:00
Arthur O'Dwyer 7e1355eb13 [libc++] Mark __wrap_iter's private constructors as explicit.
This is slightly more user-visible than D119894, because the user is
expected to touch `__wrap_iter` directly. But the affected ctors are
non-public, so the user was never expected to be actually calling them.
And I didn't intentionally omit this from D119894; I just didn't
think of it.

Differential Revision: https://reviews.llvm.org/D120937
2022-03-04 13:24:38 -05:00
Nikolas Klauser bd44174547 [libc++] Use -I instead of -isystem to include headers in the test suite
Using -isystem marks the headers as system headers, which means that we
don't actually get all the warnings that we'd normally get if we included
the headers as user headers.

The goal of the test suite is normally to mirror as closely as possible
how users would use the library. Technically, this change goes against
that philosophy, since users should be using `-isystem` (if they ever
need to specify the libc++ path explicitly, which should be a rare
occurence). However, I believe fishing out additional warnings from
the headers provides more value, hence this change. Ideally, we'd be
able to still use `-isystem`, but instruct Clang to still emit warnings
from the libc++ headers (e.g. we could tell Clang to emit warnings in
any file inside `<...>/usr/include/c++/v1`).

Reviewed By: #libc, ldionne, #libc_abi

Spies: Mordante, EricWF, mstorsjo, mgorny, aheejin, arichardson, philnik, jloser, libcxx-commits

Differential Revision: https://reviews.llvm.org/D118616
2022-03-03 13:19:47 +01:00
Arthur O'Dwyer dc1c67624b [libc++] Preliminary cleanups to ranges::iter_move. NFC.
This is just getting some non-functional cleanups out of the way
prior to the meat of the change in D120417.
2022-03-02 17:51:17 -05:00
Arthur O'Dwyer f86c2b6f1f [libc++] Add `explicit` to a bunch of internal detail ctors.
Notably the following ctors remain non-explicit because they
are used as implicit conversions in too many places:
* __debug_less(_Compare&)
* __map_iterator(_TreeIterator)
* __map_const_iterator(_TreeIterator)
* __hash_map_iterator(_HashIterator)
* __hash_map_const_iterator(_HashIterator)

Differential Revision: https://reviews.llvm.org/D119894
2022-03-01 14:37:06 -05:00
Louis Dionne 368faacac7 [libc++] Revert "Protect users from relying on detail headers" & related changes
This commit reverts 5aaefa51 (and also partly 7f285f48e7 and b6d75682f9,
which were related to the original commit). As landed, 5aaefa51 had
unintended consequences on some downstream bots and didn't have proper
coverage upstream due to a few subtle things. Implementing this is
something we should do in libc++, however we'll first need to address
a few issues listed in https://reviews.llvm.org/D106124#3349710.

Differential Revision: https://reviews.llvm.org/D120683
2022-03-01 08:20:24 -05:00
Arthur O'Dwyer d4853e638b [libc++] [ranges] Permit std::mergeable and std::sortable with HAS_NO_INCOMPLETE_RANGES.
This follows the general direction of D118736 that
`_LIBCPP_HAS_NO_INCOMPLETE_RANGES` does *not* guard anything outside
of the `std::ranges::` namespace itself. This means we must permit
`ranges::less` etc. in no-ranges mode; that seems fine to me.

Differential Revision: https://reviews.llvm.org/D120139
2022-02-28 14:56:01 -05:00
Christopher Di Bella 5aaefa510e [libcxx][modules] protects users from relying on detail headers
libc++ has started splicing standard library headers into much more
fine-grained content for maintainability. It's very likely that outdated
and naive tooling (some of which is outside of LLVM's scope) will
suggest users include things such as <__ranges/access.h> instead of
<ranges>, and Hyrum's law suggests that users will eventually begin to
rely on this without the help of tooling. As such, this commit
intends to protect users from themselves, by making it a hard error for
anyone outside of the standard library to include libc++ detail headers.

Differential Revision: https://reviews.llvm.org/D106124
2022-02-26 09:00:25 +00:00
Konstantin Varlamov 8e979460bb [libc++][ranges] Implement `std::sortable`.
Differential Revision: https://reviews.llvm.org/D119619
2022-02-17 20:17:42 -08:00
Konstantin Varlamov eea3d90af1 [libc++][ranges] Implement `std::mergeable`.
Differential Revision: https://reviews.llvm.org/D119489
2022-02-17 20:12:04 -08:00
Nikolas Klauser 318507edee [libc++] Remove a few unneeded _LIBCPP_CXX03_LANG ifdefs
Reviewed By: Quuxplusone, ldionne, #libc

Spies: libcxx-commits

Differential Revision: https://reviews.llvm.org/D119896
2022-02-17 00:14:42 +01:00
Louis Dionne f87aa19be6 [libc++] Move everything related solely to _LIBCPP_ASSERT to its own file
This is the first step towards disentangling the debug mode and assertions
in libc++. This patch doesn't make any functional change: it simply moves
_LIBCPP_ASSERT-related stuff to its own file so as to make it clear that
libc++ assertions and the debug mode are different things. Future patches
will make it possible to enable assertions without enabling the debug
mode.

Differential Revision: https://reviews.llvm.org/D119769
2022-02-16 12:49:50 -05:00
Konstantin Varlamov 43bc1e5600 [libc++][ranges] Implement Ranges changes to `istream{,buf}_iterator`.
The changes from the One Ranges Proposal amount to adding:
- a constructor that takes a `default_sentinel_t` and is equivalent to
  the default constructor;
- an `operator==` that compares the iterator to `default_sentinel_t`.

The original proposal defined two overloads for `operator==` (different
argument order) as well as `operator!=`. This has been removed by
[P1614](https://wg21.link/p1614).

Differential Revision: https://reviews.llvm.org/D119620
2022-02-15 16:59:42 -08:00