Commit Graph

3712 Commits

Author SHA1 Message Date
Arthur O'Dwyer 67151d029b [libc++] [ranges] Implement P2415R2 owning_view.
"What is a view?"
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2415r2.html
https://github.com/cplusplus/draft/pull/5010/files

This was a late-breaking (Oct 2021) change to C++20.
The only thing missing from this patch is that we're supposed
to bump the feature-test macro from
    #define __cpp_lib_ranges 202106L
to
    #define __cpp_lib_ranges 202110L
but we can't do that because we don't implement all of 202106 Ranges yet.

Differential Revision: https://reviews.llvm.org/D116894
2022-01-13 12:29:41 -05:00
Arthur O'Dwyer 42185ad870 [libc++] Add tests verifying alphabetical order for several things.
These things are header #includes, CMakeLists.txt, and module.modulemap.

Differential Revision: https://reviews.llvm.org/D116958
2022-01-13 09:58:56 -05:00
Arthur O'Dwyer 483f7f5536 [libc++] [ranges] Implement ranges::cdata.
Differential Revision: https://reviews.llvm.org/D117044
2022-01-12 22:07:13 -05:00
Konstantin Varlamov b9bc3c107c [libc++][ranges] Implement `construct_at` and `destroy{,_at}`.
Differential Revision: https://reviews.llvm.org/D116078
2022-01-12 16:01:04 -08:00
Arthur O'Dwyer 9be193bc58 [libc++] [ranges] Finish ADL-proofing ranges::data.
This should have been part of D116239.
2022-01-12 18:16:22 -05:00
Arthur O'Dwyer 4163f61f29 [libc++] [ranges] Fix a missing auto(x) cast in ranges::data.
Also remove some bogus `std::forward`s. My impression is that these
forwards were actually harmless, because `ranges::begin(FWD(t))` is
always identical to `ranges::begin(t)` (except when it's ill-formed,
and that can't happen in this case). However, they're also superfluous
and don't reflect the wording in the standard, so let's eliminate them.

Differential Revision: https://reviews.llvm.org/D117043
2022-01-12 18:16:15 -05:00
Arthur O'Dwyer a70fe03961 [libc++] [ranges] SFINAE away ranges::cbegin(const T&&) for non-borrowed T.
Fixes #52952.

Differential Revision: https://reviews.llvm.org/D116991
2022-01-12 13:25:41 -05:00
Louis Dionne d202c76441 [libc++] Start using `arc4random()` to implement `std::random_device` on Apple
On Apple platforms, arc4random is faster than /dev/urandom, and it is
the recommended user-space RNG according to Apple's own OS folks.

This commit adds an ABI switch to guard ABI-break-protections in
std::random_device, and starts using arc4random instead of /dev/urandom
to implement std::random_device on Apple platforms.

Note that previously, `std::random_device` would allow passing a custom
token to its constructor, and that token would be interpreted as the name
of a file to read entropy from. This was implementation-defined and
undocumented. After this change, Apple platforms will be using arc4random()
instead, and any custom token passed to the constructor will be ignored.
This behavioral change will also impact other platforms that use the
arc4random() implementation, such as OpenBSD. This should be fine since
that is effectively a relaxation of the constructor's requirements.

rdar://86638350

Differential Revision: https://reviews.llvm.org/D116045
2022-01-12 11:24:23 -05:00
Nikolas Klauser fcfc0e7ad3 [libc++] Introduce __fits_in_sso()
Introduce `__fits_in_sso()` to put the constexpr tests into a central place.

Reviewed By: ldionne, #libc

Spies: libcxx-commits

Differential Revision: https://reviews.llvm.org/D116487
2022-01-11 23:20:15 +01:00
Nikolas Klauser e3cf70502c [libc++] Introduce __debug_db_insert_c()
There are a lot of
```
#if _LIBCPP_DEBUG_LEVEL == 2
    __get_db()->__insert_c(this);
#endif
```

This patch introduces `__debug_db_insert_c()` to put the `#if` in one central place.

Reviewed By: ldionne, #libc

Spies: libcxx-commits

Differential Revision: https://reviews.llvm.org/D116947
2022-01-11 23:11:26 +01:00
Konstantin Varlamov 8d23b7420c [libc++][ranges] Implement `uninitialized_copy{,_n}` and `uninitialized_move{,_n}`.
Also implement `in_out_result` which is a prerequisite.

Differential Revision: https://reviews.llvm.org/D116023
2022-01-10 22:49:50 -08:00
Nikolas Klauser 2154dbaa59 [libc++][NFC] Use _LIBCPP_DEBUG_ASSERT in <list>
Use `_LIBCPP_DEBUG_ASSERT` in `<list>`

Reviewed By: Quuxplusone, ldionne, #libc

Spies: libcxx-commits

Differential Revision: https://reviews.llvm.org/D116938
2022-01-10 23:19:16 +01:00
Arthur O'Dwyer 4d81a46f7f [libc++] Alphabetize header #includes. NFCI.
The NFC part of D116809. We still want to enforce this in CI,
but the mechanism for that is still to-be-determined.

Differential Revision: https://reviews.llvm.org/D116809
2022-01-10 16:30:38 -05:00
Arthur O'Dwyer c9f83a8af9 [libc++] Alphabetize CMakeLists.txt and module.modulemap. NFC.
The NFC part of D116958. We still want to enforce this in CI,
but the mechanism for that is still to-be-determined.
2022-01-10 15:38:40 -05:00
Arthur O'Dwyer 07a0b0ee94 [libc++] Properly handle specializations of std::is_placeholder.
Before this patch, the user needed to specialize both of
`is_placeholder<MyType>` and `is_placeholder<const MyType>`.
After this patch, only the former is needed (although the
latter is harmless if provided).

The new tests don't actually fail unless return type deduction
is used, which is a C++14 feature. Specializing `is_placeholder`
is still allowed in C++11, though.

Fixes #51095.

Differential Revision: https://reviews.llvm.org/D116388
2022-01-10 12:38:59 -05:00
Arthur O'Dwyer 6ce732cbad [libc++] [ranges] Add namespace __cpo to ranges::{advance,next,prev}.
The reason for those nested namespaces is explained in D115315:

> AIUI, this keeps the CPO's own type from ADL'ing into the `std::ranges`
> namespace; e.g. `foobar(std::ranges::uninitialized_default_construct)`
> should not consider `std::ranges::foobar` a candidate, even if
> `std::ranges::foobar` is not a CPO itself. Also, of course, consistency
> (Chesterton's Fence, the economist's hundred-dollar bill): if it were
> safe to omit the namespace, we'd certainly want to do it everywhere,
> not just here.

This makes these three niebloids more consistent with the other Ranges
niebloids we've already implemented, such as the `ranges::begin` group
and the `ranges::uninitialized_default_construct` group.

FWIW, we still have three different indentation-and-comment styles
among these three groups.

Differential Revision: https://reviews.llvm.org/D116569
2022-01-08 12:47:54 -05:00
Arthur O'Dwyer 004ebe22f8 [libc++] Add missing templated version of `std::lerp`.
Fixes #50806.

Differential Revision: https://reviews.llvm.org/D116295
2022-01-07 09:55:33 -05:00
Nikolas Klauser bec50db2ed [libc++] Implement P1072R10 (std::basic_string::resize_and_overwrite)
Reviewed By: Quuxplusone, #libc, Mordante

Spies: mzeren-vmw, ckennelly, arichardson, ldionne, Mordante, libcxx-commits, Quuxplusone

Differential Revision: https://reviews.llvm.org/D113013
2022-01-07 00:09:16 +01:00
Nikolas Klauser f3aed36981 [libc++] Implement P1425R4 (Iterator pair constructors for std::stack and std::queue)
Implement P1425R4

Reviewed By: Quuxplusone, #libc, Mordante

Spies: Mordante, jloser, libcxx-commits, arichardson

Differential Revision: https://reviews.llvm.org/D115977
2022-01-06 18:55:11 +01:00
Nikolas Klauser f2277e60f4 [libc++][NFC] Reformat <__filesystem/operations.h>
Reformat `<__filesystem/operations.h>`

Reviewed By: Quuxplusone, #libc, ldionne

Spies: ldionne, libcxx-commits

Differential Revision: https://reviews.llvm.org/D116234
2022-01-06 16:15:41 +01:00
Nico Weber 085f078307 Revert "Revert D109159 "[amdgpu] Enable selection of `s_cselect_b64`.""
This reverts commit 859ebca744.
The change contained many unrelated changes and e.g. restored
unit test failes for the old lld port.
2022-01-05 13:10:25 -05:00
David Salinas 859ebca744 Revert D109159 "[amdgpu] Enable selection of `s_cselect_b64`."
This reverts commit 640beb38e7.

That commit caused performance degradtion in Quicksilver test QS:sGPU and a functional test failure in (rocPRIM rocprim.device_segmented_radix_sort).
Reverting until we have a better solution to s_cselect_b64 codegen cleanup

Change-Id: Ibf8e397df94001f248fba609f072088a46abae08

Reviewed By: kzhuravl

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

Change-Id: Id169459ce4dfffa857d5645a0af50b0063ce1105
2022-01-05 17:57:32 +00:00
Mark de Wever de731efd4c [libc++][format] Improve an exception message.
The fix in D116381 makes an existing exception message wrong. This
improves the message and fixes the associated unit tests.

Note other message can be also be improved, but that will be done later.
Changing these messages may cause merge conflicts with other patches
that are under review or WIP.

Depends on D116381

Reviewed By: #libc, Quuxplusone, ldionne

Differential Revision: https://reviews.llvm.org/D116495
2022-01-05 17:43:11 +01:00
Mark de Wever f2b40ba400 [libc++][format] Fix precision parser conformance.
@CaseyCarter reported that the tests for the std-format-spec rejects leading
zeroes for precision, which the Standard does not require. The Standard allows
them. Only for precision, not for the width or an arg-id.

Fixes the precision parser and adds some test for the arg-id since they
were missing.

Reviewed By: ldionne, #libc

Differential Revision: https://reviews.llvm.org/D116381
2022-01-05 17:41:36 +01:00
Nikolas Klauser 93746b940a [libc++] Use _LIBCPP_DEBUG_ASSERT in __iterator/wrap_iter.h
Use `_LIBCPP_DEBUG_ASSERT` in `__iterator/wrap_iter.h`

Reviewed By: #libc, Quuxplusone, Mordante, ldionne

Spies: libcxx-commits

Differential Revision: https://reviews.llvm.org/D116347
2022-01-05 09:15:42 +01:00
Nikolas Klauser cf54cb2e03 [libc++][NFC] Remove duplicate header includes from <algorithm> and reorder them
Remove duplicate header includes from `<algorithm>` and reorder the includes

Reviewed By: Quuxplusone, ldionne, Mordante, #libc, jloser

Spies: jloser, libcxx-commits

Differential Revision: https://reviews.llvm.org/D116507
2022-01-05 09:06:53 +01:00
Nikolas Klauser 6d722801d1 [libc++][ranges] Add indirectly_comparable concept
Add `indirectly_comparable` concept

Reviewed By: Quuxplusone, Mordante, #libc

Spies: mgorny, libcxx-commits

Differential Revision: https://reviews.llvm.org/D116268
2022-01-04 23:40:57 +01:00
Arthur O'Dwyer 855d7bedb7 [libc++] [P0887] Add newest feature-test macros; mark `type_identity` as implemented.
`__cpp_lib_type_identity` was implemented way back in cf49ccd0 (Clang 8),
probably before the feature-test macro had been settled on.

`__cpp_lib_string_resize_and_overwrite` will be added by D113013 so I didn't add it here.

Fixes #46605.

Differential Revision: https://reviews.llvm.org/D116433
2022-01-04 17:23:37 -05:00
Arthur O'Dwyer 8507383631 [libc++] [ranges] ADL-proof the [range.access] CPOs.
For example, `std::ranges::range<Holder<Incomplete>*>` should be
well-formed false, not a hard error at compile time.

Differential Revision: https://reviews.llvm.org/D116239
2022-01-04 17:15:42 -05:00
Arthur O'Dwyer 502e5df0e0 [libc++] Implement `ranges::{cbegin,cend}` per the spec.
The big change here is that they now work as intended for rvalues,
e.g. `ranges::cbegin(std::string_view("hello"))`.
Also, add tests verifying their return types.

Differential Revision: https://reviews.llvm.org/D116199
2022-01-04 16:18:41 -05:00
Arthur O'Dwyer e80ef6bd27 [libc++] Fix whitespace in __partial_sort. NFC. 2022-01-04 16:15:02 -05:00
Arthur O'Dwyer f6fb7bf636 [libc++] Add an early return for __partial_sort of an empty range.
If `__first == __middle`, then `partial_sort` is a no-op; don't
bother to iterate all the way from `__middle` to `__end`.

Fixes #49431.

Differential Revision: https://reviews.llvm.org/D116296
2022-01-04 16:14:05 -05:00
Mark de Wever bd6e6846e7 [libc++] Add the version header to all headers.
Some headers which require the version header depend on other headers to
provide it. Include the version header in all top-level headers to make
sure a header cleanup can't remove the version header.

Note this doesn't add the version header to the c headers.

Reviewed By: #libc, Quuxplusone, ldionne

Differential Revision: https://reviews.llvm.org/D116172
2022-01-04 19:50:59 +01:00
Roland McGrath 3064dd8ccf [libcxx] Use Fuchsia-native CPRNG for std::random_device
Use the zx_cprng_draw system call directly rather than going
through the libc getentropy function.  The libc function is a
trivial wrapper around the system call, and is not a standard C
function.  Avoiding it reduces the Fuchsia libc ABI surface that
libc++ depends on.

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D116498
2022-01-04 10:24:18 -08:00
Louis Dionne e24ddb6027 [libc++] Use std::addressof in std::function::target
This guards against hostile overloads of operator&. Thanks to Peter Dimov
for the report in https://github.com/boostorg/lambda/issues/24.

Differential Revision: https://reviews.llvm.org/D116380
2022-01-04 12:31:45 -05:00
Nikolas Klauser 875dd75e5a [libc++][NFC] Use _LIBCPP_DEBUG_ASSERT in <__hash_table>
Use `_LIBCPP_DEBUG_ASSERT` in `<__hash_table>`

Reviewed By: Quuxplusone, ldionne, Mordante, #libc

Spies: libcxx-commits

Differential Revision: https://reviews.llvm.org/D116486
2022-01-04 16:00:37 +01:00
Nikolas Klauser c9dbf0f2a1 [libc++] Fix __wrap_iter copy-assignment in constexpr contexts
Fixes https://github.com/llvm/llvm-project/issues/52902

In debug mode during constant evaluation the iterator was never assigend. There seem to be no other instances of this bug.

Reviewed By: Quuxplusone, Mordante, #libc, ldionne

Spies: ldionne, libcxx-commits

Differential Revision: https://reviews.llvm.org/D116346
2022-01-04 11:05:53 +01:00
Arthur O'Dwyer 928852f156 [libc++] [NFC] Remove an unused parameter from `__sift_down`.
Differential Revision: https://reviews.llvm.org/D116382
2021-12-29 16:25:33 -05:00
Chuanqi Xu 6441536c27 [libcxx] [Coroutines] Support noop_coroutine for GCC
We didn't support noop_coroutine for GCC in previous conforming patch.
So that GCC couldn't use noop_coroutine() defined in <coroutine>. And
after this patch, GCC should be able to compile the whole <coroutine>
header.

Reviewed By: Quuxplusone

Differential Revision: https://reviews.llvm.org/D116144
2021-12-27 13:53:21 +08:00
Arthur O'Dwyer 3042091168 [libc++] [ranges] Whitespace and namespace-style adjustments. NFC.
Largely split out of D116199 to keep that PR smaller.
2021-12-23 14:56:23 -05:00
Arthur O'Dwyer a2a9a5c7d3 [libc++] [ranges] Fix bugs in ranges::empty().
It was missing the cast to `bool` in `bool(__t.empty())`.
It was wrongly using `std::forward` in some places.

Differential Revision: https://reviews.llvm.org/D115312
2021-12-23 14:56:23 -05:00
Mark de Wever e8b24ee115 [libc++][format][NFC] Remove some unneeded headers.
Reviewed By: #libc, Quuxplusone, Mordante

Differential Revision: https://reviews.llvm.org/D116175
2021-12-23 17:38:21 +01:00
Mark de Wever dfb20d4d19 [libc++][format] Improve ABI stability.
During the review of D115991 @vitaut pointed out the enum shouldn't
depend on whether or not _LIBCPP_HAS_NO_INT128 is defined. The current
implementation lets the enum's ABI depend on this configuration option
without a good cause.

Reviewed By: ldionne, #libc

Differential Revision: https://reviews.llvm.org/D116120
2021-12-23 17:37:12 +01:00
Nikolas Klauser 23f1cd9e63 [libc++] Remove unused headers from <filesystem>
Remove unused headers from `<filesystem>`

Reviewed By: Quuxplusone, #libc, Mordante

Spies: Mordante, libcxx-commits

Differential Revision: https://reviews.llvm.org/D116146
2021-12-23 13:32:49 +01:00
Nikolas Klauser fcc0964ed4 Revert "[libc++] Remove unused headers from <filesystem>"
This reverts commit 352945dd36.
2021-12-23 11:55:38 +01:00
Nikolas Klauser 352945dd36 [libc++] Remove unused headers from <filesystem>
Remove unused headers from `<filesystem>`

Spies: libcxx-commits

Differential Revision: https://reviews.llvm.org/D116146
2021-12-23 02:07:47 +01:00
Arthur O'Dwyer caf940bac6 [libc++] Remove "clang-format off/on" comments. NFC.
These headers have stabilized; we don't expect anyone to be
blindly clang-formatting them anymore.
Leave the comments in `__format/*.h` for Mark to remove at his leisure.
2021-12-22 17:56:03 -05:00
Arthur O'Dwyer cb8a0b0797 [libc++] [ranges] Introduce _LIBCPP_AUTO_CAST(x) for auto(x).
Clang is gaining `auto(x)` support in D113393; sadly there
seems to be no feature-test macro for it. Zhihao is opening
a core issue for that macro.

Use `_LIBCPP_AUTO_CAST` where C++20 specifies we should use `auto(x)`;
stop using `__decay_copy(x)` in those places.
In fact, remove `__decay_copy` entirely. As of C++20, it's purely
a paper specification tool signifying "Return just `x`, but it was
perfect-forwarded, so we understand you're going to have to call
its move-constructor sometimes." I believe there's no reason we'd
ever need to do its operation explicitly in code.

This heisenbugs away a test failure on MinGW; see D112214.

Differential Revision: https://reviews.llvm.org/D115686
2021-12-22 12:29:42 -05:00
Arthur O'Dwyer 8ad364ad21 [libc++] [ranges] Remove the static_assert from ranges::begin and ranges::end.
As discussed with ldionne. The problem with this static_assert
is that it makes ranges::begin a pitfall for anyone ever to use
inside a constraint or decltype. Many Ranges things, such as ranges::size,
are specified as "Does X if X is well-formed, or else Y if Y is well-formed,
or else `ranges::end(t) - ranges::begin(t)` if that is well-formed, or else..."
And if there's a static_assert hidden inside `ranges::begin(t)`, then you get
a hard error as soon as you ask the question -- even if the answer would have
been "no, that's not well-formed"!

Constraining on `requires { t + 0; }` or `requires { t + N; }` is verboten
because of https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103700 . For ranges::begin,
we can just decay to a pointer even in the incomplete-type case. For ranges::end,
we can safely constrain on `sizeof(*t)`. Yes, this means that an array of incomplete
type has a `ranges::begin` but no `ranges::end`... just like an unbounded array of
complete type. This is a valid manifestation of IFNDR.

All of the new libcxx/test/std/ cases are mandatory behavior, as far as I'm aware.
Tests for the IFNDR cases in ranges::begin and ranges::end remain in `libcxx/test/libcxx/`.
The similar tests for ranges::empty and ranges::data were simply wrong, AFAIK.

Differential Revision: https://reviews.llvm.org/D115838
2021-12-22 10:33:17 -05:00
Nikolas Klauser 7056250f51 [libc++][NFC] Granularize <filesystem>
Granularize the `<filesystem>` header

Reviewed By: Quuxplusone, ldionne, #libc

Spies: libcxx-commits, mgorny

Differential Revision: https://reviews.llvm.org/D115578
2021-12-22 02:31:17 +01:00