Commit Graph

3274 Commits

Author SHA1 Message Date
zoecarver c40b02608e [libcxx][ranges] Implement `ranges::borrowed_range`.
Differential Revision: https://reviews.llvm.org/D102426
2021-05-20 11:51:44 -07:00
Christopher Di Bella d8fad66149 [libcxx][ranges] adds concept `sized_range` and cleans up `ranges::size`
* adds `sized_range` and conformance tests
* moves `disable_sized_range` into namespace `std::ranges`
* removes explicit type parameter

Implements part of P0896 'The One Ranges Proposal'.

Differential Revision: https://reviews.llvm.org/D102434
2021-05-19 18:16:45 +00:00
Amy Huang 7c2f58278e Apply [[standalone_debug]] to some types in the STL.
Add this attribute to some types to ensure that they have
debug info.
The debug info for these classes are required for debuggers to display
some STL types. With constructor homing (a new debug info optimization)
their debug info isn't emitted because their constructors are never
called.

The list of types with the attribute added are __hash_value_type,
__value_type, __tree_node_base, __tree_node, __hash_node, __list_node,
and __forward_list_node.

Differential Revision: https://reviews.llvm.org/D98750
2021-05-18 17:01:07 -07:00
Arthur O'Dwyer 06b40e80ae [libc++] Alphabetize header inclusions and include-what-you-use <__debug>. NFCI. 2021-05-18 19:56:30 -04:00
Arthur O'Dwyer e130fbe24e [libc++] Some fixes to the <bit> utilities.
Fix __bitop_unsigned_integer and rename to __libcpp_is_unsigned_integer.
There are only five unsigned integer types, so we should just list them out.
Also provide `__libcpp_is_signed_integer`, even though the Standard doesn't
consume that trait anywhere yet.

Notice that `concept uniform_random_bit_generator` is specifically specified
to rely on `concept unsigned_integral` and *not* `__is_unsigned_integer`.
Instantiating `std::ranges::sample` with a type `U` satisfying
`uniform_random_bit_generator` where `unsigned_integral<U::result_type>`
and not `__is_unsigned_integer<U::result_type>` is simply IFNDR.

Orthogonally, fix an undefined behavior in std::countr_zero(__uint128_t).

Orthogonally, improve tests for the <bit> manipulation functions.
It was these new tests that detected the bug in countr_zero.

Differential Revision: https://reviews.llvm.org/D102328
2021-05-18 19:56:30 -04:00
Kristina Bessonova a18b5f0188 [libcxx] NFC. Add missed articles to _LIPCPP_ASSERT messages in <list> 2021-05-17 10:15:43 +02:00
zoecarver bede7523b1 [libcxx][ranges] Add `contiguous_iterator`.
Differential Revision: https://reviews.llvm.org/D101396
2021-05-14 15:27:40 -07:00
zoecarver 98e4fd0701 [libcxx][ranges] Fix `ranges::empty` when begin, end, and empty members are provided.
Before this commit, we'd get a compilation error because the operator() overload was ambiguous.

Differential Revision: https://reviews.llvm.org/D102263
2021-05-13 10:07:57 -07:00
Kristina Bessonova 8a86787847 [libcxx] NFC. Fix misprint unodered -> unordered
Differential Revision: https://reviews.llvm.org/D102354
2021-05-13 09:57:29 +02:00
Christopher Di Bella 46c17429bc [libcxx] modifies `_CmpUnspecifiedParam` ignore types outside its domain
D85051's honeypot solution was a bit too aggressive swallowed up the
comparison types, which made comparing objects of different ordering
types ambiguous.

Depends on D101707.

Differential Revision: https://reviews.llvm.org/D101708
2021-05-13 00:45:39 +00:00
Mark de Wever c273f5ef7d [libc++][nfc] remove duplicated __to_unsigned.
Both `<type_traits>` and `<charconv>` implemented this function with
different names and a slightly different behavior. This removes the
version in `<charconv>` and improves the version in `<typetraits>`.

- The code can be used again in C++11.
-  The original claimed C++14 support, but `[[nodiscard]]` is not
   available in  C++14.
- Adds `_LIBCPP_INLINE_VISIBILITY`.

Reviewed By: zoecarver, #libc, Quuxplusone

Differential Revision: https://reviews.llvm.org/D102332
2021-05-12 21:09:49 +02:00
Kristina Bessonova 96100f1508 [libcxx] NFC. Correct wordings of _LIBCPP_ASSERT debug messages
Differential Revision: https://reviews.llvm.org/D102195
2021-05-12 13:49:57 +02:00
Arthur O'Dwyer 6491d99e33 [libc++] Remove more unnecessary _VSTD:: from type names. NFCI.
Differential Revision: https://reviews.llvm.org/D102181
2021-05-11 12:23:55 -04:00
Arthur O'Dwyer 866b27950a [libc++] s/_VSTD::is_unsigned/is_unsigned/ in <random>. NFCI. 2021-05-11 12:23:55 -04:00
Arthur O'Dwyer aa5e3beea3 [libc++] s/_VSTD::chrono/chrono/g. NFCI. 2021-05-11 12:23:55 -04:00
Arthur O'Dwyer 0b8da5fa59 [libc++] s/std::size_t/size_t/g. NFCI. 2021-05-11 12:23:55 -04:00
Arthur O'Dwyer ab3fcc5065 [libc++] s/_VSTD::declval/declval/g. NFCI. 2021-05-11 12:23:55 -04:00
Christopher Di Bella 578d09c1b1 [libcxx] deprecates/removes `std::raw_storage_iterator`
C++17 deprecates `std::raw_storage_iterator` and C++20 removes it.

Implements part of:
  * P0174R2 'Deprecating Vestigial Library Parts in C++17'
  * P0619R4 'Reviewing Deprecated Facilities of C++17 for C++20'

Differential Revision: https://reviews.llvm.org/D101730
2021-05-11 06:43:29 +00:00
Christopher Di Bella 9eb0969a76 [libcxx] makes comparison operators for `std::*_ordering` types hidden friends
The standard leaves it up to the implementation to decide whether or not
these operators are hidden friends. There are several (well-documented)
reasons to prefer hidden friends, as well as an argument for improved
readability.

Depends on D100342.

Differential Revision: https://reviews.llvm.org/D101707
2021-05-11 06:41:45 +00:00
Christopher Di Bella 20506fb1f3 [libcxx] removes operator!= and globally guards against no spaceship operator
* `operator!=` isn't in the spec
* `<compare>` is designed to work with `operator<=>` so it doesn't
  really make sense to have `operator<=>`-less friendly sections.

Depends on D100283.

Differential Revision: https://reviews.llvm.org/D100342
2021-05-11 06:40:54 +00:00
zoecarver e5d483f28a [libcxx][ranges] Add ranges::empty CPO.
Depends on D101079. Refs D101189.

Differential Revision: https://reviews.llvm.org/D101193
2021-05-10 17:14:39 -07:00
Christopher Di Bella 4ff2fe1df0 [libcxx] removes `weak_equality` and `strong_equality` from <compare>
`weak_equality` and `strong_equality` were removed before being
standardised, and need to be removed.

Also adjusts `common_comparison_category` since its test needed
adjusting due to the equality deletions.

Differential Revision: https://reviews.llvm.org/D100283
2021-05-10 20:45:04 +00:00
Mark de Wever cfef7c918b [libc++][NFC] Remove _VSTD:: when not needed.
Reviewed By: #libc, Quuxplusone

Differential Revision: https://reviews.llvm.org/D102133
2021-05-10 18:15:50 +02:00
Louis Dionne fe0e86e602 [libc++] Rewrite std::to_address to avoid relying on element_type
This is a rough reapplication of the change that fixed std::to_address
to avoid relying on element_type (da456167). It is somewhat different
because the fix to avoid breaking Clang (which caused it to be reverted
in 347f69c55) was a bit more involved.

Differential Revision: https://reviews.llvm.org/D101638
2021-05-06 10:14:11 -04:00
Arthur O'Dwyer 9571b8f238 [libc++] [LIBCXX-DEBUG-FIXME] std::advance shouldn't use ADL `>=` on the _Distance type.
Convert to a primitive type first; then use primitive `>=` on that value.

Differential Revision: https://reviews.llvm.org/D101678
2021-05-05 16:21:09 -04:00
Arthur O'Dwyer db9425cb06 [libc++] [LIBCXX-DEBUG-FIXME] Fix an iterator-invalidation issue in string::assign.
This appears to be a bug in our string::assign: when assigning into
a longer string, from a shorter snippet of itself, we invalidate
iterators before doing the copy. We should invalidate them afterward.
Also drive-by improve the formatting of a function header.

Differential Revision: https://reviews.llvm.org/D101675
2021-05-05 16:20:53 -04:00
Arthur O'Dwyer 0b10bb7ddd [libc++] Move <__sso_allocator> out of include/ into src/. NFCI.
This allocator is not intended for libc++'s users to use;
it's strictly an implementation detail of `src/locale.cpp`.
So, move it to the `src/include/` directory.

Drive-by const-qualify its comparison operators.

For consistency with `__hidden_allocator` (defined in `src/thread.cpp`),
do *not* remove it from "libcxx/lib/libc++unexp.exp",
"libcxx/utils/symcheck-blacklists/linux_blacklist.txt", etc.

Differential Revision: https://reviews.llvm.org/D101293
2021-05-05 16:20:52 -04:00
zoecarver 6f1b10df91 [libcxx][ranges] Add ranges::ssize CPO.
Based on D101079.

Differential Revision: https://reviews.llvm.org/D101189
2021-05-04 21:50:00 -07:00
zoecarver 600686d75f [libcxx][ranges] Add ranges::size CPO.
The begining of [range.prim].

Differential Revision: https://reviews.llvm.org/D101079
2021-05-04 21:50:00 -07:00
zoecarver 6ffc41b014 [libcxx][ranges] Add `random_access_{iterator,range}`.
Differential Revision: https://reviews.llvm.org/D101316
2021-05-04 21:42:55 -07:00
Louis Dionne 347f69c55f [libc++] Revert the std::to_address change to avoid relying on element_type.
This reverts commit da456167, which broke the Clang build. I'm able to
reproduce it but I want to give myself a bit more time to investigate.

Differential Revision: https://reviews.llvm.org/D101638
2021-05-04 18:50:05 -04:00
Arthur O'Dwyer da456167f5 [libc++] Make sure std::to_address doesn't depend on P::element_type.
Differential Revision: https://reviews.llvm.org/D101638
2021-05-04 16:59:25 -04:00
Louis Dionne 17f2d1cb9b [libc++] Fix QoI bug with construction of std::tuple involving std::any
In std::tuple, we should try to avoid calling std::is_copy_constructible
whenever we can to avoid surprising interactions with (I believe) compiler
builtins. This bug was reported in https://reviews.llvm.org/D96523#2730953.

The issue was that when tuple<_Up...> was the same as tuple<_Tp...>, we
would short-circuit the _Or (because sizeof...(_Tp) != 1) and go evaluate
the following `is_constructible<_Tp, const _Up&>...`. That shouldn't
actually be a problem, but see the analysis in https://reviews.llvm.org/D101770#2736470
for why it is with Clang and GCC.

Instead, after this patch, we check whether the constructed-from tuple
is the same as the current tuple regardless of the number of elements,
since we should always prefer the normal copy constructor in that case
anyway.

Differential Revision: https://reviews.llvm.org/D101770
2021-05-04 16:42:36 -04:00
Louis Dionne 2021d272ad [libc++] Implement ranges::view
Differential Revision: https://reviews.llvm.org/D101547
2021-05-04 11:05:58 -04:00
Christopher Di Bella 9c5d86aac5 [libcxx][iterator][ranges] adds `bidirectional_iterator` and `bidirectional_range`
Implements parts of:
    * P0896R4 The One Ranges Proposal`

Depends on D100275.

Differential Revision: https://reviews.llvm.org/D100278
2021-05-03 21:21:33 +00:00
Christopher Di Bella fa3e26266c [libcxx][iterator][ranges] adds `forward_iterator` and `forward_range`
Implements parts of:
    * P0896R4 The One Ranges Proposal`

Depends on D100271.

Differential Revision: https://reviews.llvm.org/D100275
2021-05-03 20:46:18 +00:00
Louis Dionne 84f0bb6195 [libc++] Fix template instantiation depth issues with std::tuple
This fixes the issue by implementing _And using the short-circuiting
SFINAE trick that we previously used only in std::tuple. One thing we
could look into is use the naive recursive implementation for disjunctions
with a small number of arguments, and use that trick with larger numbers
of arguments. It might be the case that the constant overhead for setting
up the SFINAE trick makes it only worth doing for larger packs, but that's
left for further work.

This problem was raised in https://reviews.llvm.org/D96523.

Differential Revision: https://reviews.llvm.org/D101661
2021-05-03 14:42:07 -04:00
Louis Dionne 49e7be2e5b [libc++] Disentangle std::pointer_safety
This patch gets rid of technical debt around std::pointer_safety which,
I claim, is entirely unnecessary. I don't think anybody has used
std::pointer_safety in actual code because we do not implement the
underlying garbage collection support. In fact, P2186 even proposes
removing these facilities entirely from a future C++ version. As such,
I think it's entirely fine to get rid of complex workarounds whose goals
were to avoid breaking the ABI back in 2017.

I'm putting this up both to get reviews and to discuss this proposal for
a breaking change. I think we should be comfortable with making these
tiny breaks if we are confident they won't hurt anyone, which I'm fairly
confident is the case here.

Differential Revision: https://reviews.llvm.org/D100410
2021-05-03 14:33:49 -04:00
Martin Storsjö 8d0dfa0d57 [libcxx] Reenable ranges for clang-cl
This reverts a224bf8ec4 and fixes the
underlying issue.

The underlying issue is simply that MSVC headers contains a define
like "#define __in", where __in is one macro in the MSVC Source
Code Annotation Language, defined in sal.h

Just use a different variable name than "__in"
__indirectly_readable_impl, and add "__in" to nasty_macros.h just
like the existing __out. (Also adding a couple more potentially
conflicting ones.)

Differential Revision: https://reviews.llvm.org/D101613
2021-05-01 11:15:38 +03:00
Arthur O'Dwyer 6946f0ecca [libc++] [LIBCXX-DEBUG-FIXME] <span>, like <string_view>, has no use for debug iterators.
A span has no idea what container (if any) "owns" its iterators, nor
under what circumstances they might become invalidated.

However, continue to use `__wrap_iter<T*>` instead of raw `T*` outside
of debug mode, because we've been shipping `std::span` since Clang 7
and ldionne doesn't want to break ABI. (Namely, the mangling of functions
taking `span::iterator` as a parameter.) Permit using raw `T*` there,
but only under an ABI macro: `_LIBCPP_ABI_SPAN_POINTER_ITERATORS`.

Differential Revision: https://reviews.llvm.org/D101003
2021-04-30 23:06:45 -04:00
Arthur O'Dwyer 7e9cf2075a [libc++] s/begin.h/access.h/ in comments. NFCI. 2021-04-30 20:07:00 -04:00
Christopher Di Bella c05d1eed35 [libcxx][iterator][ranges] adds `input_iterator` and `input_range`
Implements parts of:
    * P0896R4 The One Ranges Proposal`

Depends on D100269.

Differential Revision: https://reviews.llvm.org/D100271
2021-04-30 22:49:06 +00:00
Louis Dionne ef89e8ca1c [libc++] Fix constexpr-ness of std::tuple's constructor
Mentioned in https://reviews.llvm.org/D96523.
2021-04-30 15:55:10 -04:00
Petr Hosek dcbfb6f873 [libcxx] Use joined format for include flag on Windows
Without this, CMake deduplicates the /I flag breaking the build. See
https://cmake.org/cmake/help/v3.13/command/target_compile_options.html
for more details on why this is needed.

Differential Revision: https://reviews.llvm.org/D101550
2021-04-30 11:40:30 -07:00
Christopher Di Bella 7c17731596 [libcxx][ranges] adds `ranges::range`, `ranges::common_range`, and range aliases
* `std::ranges::range`
* `std::ranges::sentinel_t`
* `std::ranges::range_difference_t`
* `std::ranges::range_value_t`
* `std::ranges::range_reference_t`
* `std::ranges::range_rvalue_reference_t`
* `std::ranges::common_range`

`range_size_t` depends on `sized_range` and will be added alongside it.

Implements parts of:
    * P0896R4 The One Ranges Proposal`

Depends on D100255.

Differential Revision: https://reviews.llvm.org/D100269
2021-04-30 16:56:42 +00:00
Christopher Di Bella 5a3309f825 [libcxx][ranges] adds `range` access CPOs
* `std::ranges::begin`
* `std::ranges::cbegin`
* `std::ranges::end`
* `std::ranges::cend`
* `std::ranges::iterator` (required for `end`)

Implements parts of:
    * P0896R4 The One Ranges Proposal`

Co-author: @zoecarver

Depends on D90999, D100160.

Differential Revision: https://reviews.llvm.org/D100255
2021-04-30 16:56:42 +00:00
Arthur O'Dwyer 5f51fb3421 [libc++] Minor cleanups in <iterator>. NFCI. 2021-04-30 08:52:58 -04:00
Mark de Wever 9393060f90 [libc++] Fixes std::to_chars for bases != 10.
While working on D70631, Microsoft's unit tests discovered an issue.
Our `std::to_chars` implementation for bases != 10 uses the range
`[first,last)` as temporary buffer. This violates the contract for
to_chars:
[charconv.to.chars]/1 http://eel.is/c++draft/charconv#to.chars-1
`to_chars_result to_chars(char* first, char* last, see below value, int base = 10);`
"If the member ec of the return value is such that the value is equal to
the value of a value-initialized errc, the conversion was successful and
the member ptr is the one-past-the-end pointer of the characters
written."

Our implementation modifies the range `[member ptr, last)`, which causes
Microsoft's test to fail. Their test verifies the buffer
`[member ptr, last)` is unchanged. (The test is only done when the
conversion is successful.)

While looking at the code I noticed the performance for bases != 10 also
is suboptimal. This is tracked in D97705.

This patch fixes the issue and adds a benchmark. This benchmark will be
used as baseline for D97705.

Reviewed By: #libc, Quuxplusone, zoecarver

Differential Revision: https://reviews.llvm.org/D100722
2021-04-29 19:56:28 +02:00
Petr Hosek ea12d779bc [libc++] Support per-target __config_site in per-target runtime build
When using the per-target runtime build, it may be desirable to have
different __config_site headers for each target where all targets cannot
share a single configuration.

The layout used for libc++ headers after this change is:

```
include/
  c++/
    v1/
      <libc++ headers except for __config_site>
  <target1>/
    c++/
      v1/
        __config_site
  <target2>/
    c++/
      v1/
        __config_site
  <other targets>
```

This is the most optimal layout since it avoids duplication, the only
headers that's per-target is __config_site, all other headers are
shared across targets. This also means that we no need two
-isystem flags: one for the target-agnostic headers and one for
the target specific headers.

Differential Revision: https://reviews.llvm.org/D89013
2021-04-28 14:27:16 -07:00
zoecarver bdd6835790 [libc++][ranges] iterator.concept.sizedsentinel: sized_sentinel_for and disable_sized_sentinel_for.
Based on D100160.

Reviewed By: cjdb, ldionne, Quuxplusone, #libc, miscco

Differential Revision: https://reviews.llvm.org/D100587
2021-04-26 15:06:19 -07:00