Certain headers require `optional<T&>`, so it may be beneficial to split
out `optional<T>` and `optional<T&>`. This can allow consumers to only
bring in the `optional` flavour it needs..
- Parcel out the respective pieces into their own header.
- Certain sources rely on transitive includes brought in by
`<optional>`, so they're kept there for now, and only tests have been
fixed.
---------
Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
Fixes#99984
Implement P0528R3 The Curious Case of Padding Bits, Featuring Atomic
Compare-and-Exchange
The unit test padding.pass.cpp is assisted by Cursor. However, all tests
have been modified to test what I wanted to test
---------
Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
This PR adds a parallel version of `std::mismatch` as one of the backend
operations.
It also provides an implementation based on `__pstl::__parallel_find()`
which does the heavy lifting.
`libdispatch` and `std_thread` backends expose this implementation under
their backend tags, while the `serial` backend redirects the calls to
the serial `std::mismatch`.
4 flavours of the function are exposed: 3-legged, 3-legged with
predicate, 4-legged, 4-legged with predicate.
3-legged flavours are implemented in the `default` (`composition`)
backend by redirecting the call to the 4-legged flavours.
Included tests check that:
- Semantics of the iterator-only functions is correct.
- Semantics of the predicated functions is correct.
- Custom types are supported by the implementation.
- The functions correctly SFINAE out when the first argument is not an
execution policy.
- The `nodiscard` policy is followed.
- The `noexcept` policy is followed.
- `static_assert` verifies iterators' categories.
Part of #99938.
Papers:
- P0792R14: function_ref: a type-erased callable reference
- P3948R1 constant_wrapper is the only tool needed for passing constant
expressions via function arguments
- P3961R1 Less double indirection in function_ref (RU-220)
LWG issues:
- LWG4256: Incorrect constraints for function_ref constructors from
nontype_t
- LWG4425: CTAD function_ref of data member pointer should produce
noexcept signature
Fixes#189606Fixes#105376Fixes#189604Fixes#171321Fixes#171387
---------
Co-authored-by: Xiaoyang Liu <siujoeng.lau@gmail.com>
Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
While these algorithms are conceptually related to other
`uninitialized_*` algorithms, they're likely only ever going to be used
by `shared_ptr`. `uninitialized_algorithms.h` itself is also getting
rather large, so it makes sense to split the multidimensional versions
into their own header.
Fixes#207417
This makes printing `thread::id` faster, since we avoid a bunch of
boilerplate code that isn't optimized away. It also avoids including
`<sstream>` and `<__locale>`, cutting the time to parse `<thread>` in
half.
This also changes the output when printing the id on a platform that
uses a pointer as the underlying type. I don't think that's a problem,
since the thread id isn't in any way stable. It also makes the output
consistent across all platforms we support.
This commit adds an alternative representation for `std::vector` in a similar
manner to `__split_buffer` in #139632. This alternative representation was
measured to provide significant performance gains over the classic representation.
To do so, we introduce a layout type that tracks implementation details that
differ between the pointer-based vector and size-based vector representations.
`vector` does not parameterise its layout type, unlike `__split_buffer`.
`__split_buffer` is used by both `vector` and `deque`, and being able to take
an ABI break on `vector` doesn't automatically mean that users can also tolerate
a break on `deque`.
This new vector representation can be opted into by defining the
_LIBCPP_ABI_VECTOR_LAYOUT_SIZE_BASED macro when configuring the
library's ABI.
This change was the target of this RFC: https://discourse.llvm.org/t/adding-a-size-based-vector-to-libc-s-unstable-abi
We currently have `[system]` attributes in the modulemap, which
automatically makes the headers inside the module system headers. This
disables warnings when running the tests, which we generally don't want.
We also already have `#pragma GCC system_header` everywhere and use
`-isystem`, so there isn't much need for the tag in the modulemap as
well.
Resolves#105373, resolves#118371 and resolves#105332
- Implements `<text_encoding>`
- Adds availability macros for LLVM 23.
- The data is stored in three tables:
- One giant string split by null-terminators to represent the aliases
- An index table which stores indexes into the string, each entry
representing the first character of an alias
- Text encoding data, which stores an index to the index table, the MIB,
and the number of aliases the encoding has.
Storing it in the above manner allows us to make significant savings in
binary file size and required runtime storage for the data.
As required by the LLVM Project's AI use policy:
- The implementation for `__get_locale_encoding(const char*)` for
Windows has been developed with the assistance of AI.
---------
Co-authored-by: A. Jiang <de34@live.cn>
We don't actually need to evaluate anything as lazily as `_Lazy` does or
we can achieve the same amount of laziness in other ways, so we can get
rid of it. This was required previously in some places due to a Clang
bug, which has been resolved and implemented by all compilers we
support.
Closes#105419Closes#105348Closes#105349Closes#171314
Assisted-by: Chatgpt.
I use AI to help me write some tests, however. I have reviewed the code
I submit in the tests.
---------
Co-authored-by: A. Jiang <de34@live.cn>
Co-authored-by: Hristo Hristov <hghristov.rmm@gmail.com>
Co-authored-by: Hristo Hristov <zingam@outlook.com>
We've updated the supported AppleClang version, so we can drop those
workarounds now.
This also removes `__is_referenceable_v`, since it's no longer used.
This patch introduces a new `__in_out_result`, which is an internal
back-ported version of `in_out_result`, and is convertible to that when
it exists. This improves the readability of the code, since it replaces
uses of `first` and `second` with `__in_` and `__out_`, making it clear
which iterator is accessed.
Other algorithms will be updated in separate patches.
`__is_primary_template` is only used in C++20 and later, so we can
replace it with a concept, which is significantly faster than the
current SFINAE machinery. In my testig this reduces the time to
instantiate `std::ranges::find_first_of` from ~48ms to ~40ms.
This also inlines the single remaining use of `_IsValidExpansion`.
This patch introduces `_LIBCPP_{BEGIN/END}_EXPLICIT_ABI_ANNOTATIONS` and
marks everything within an
`_LIBCPP_{BEGIN,END}_UNVERSIONED_NAMESPACE_STD` (and any derivatives
like `_LIBCPP_{BEGIN,END}_NAMESPACE_STD`) implicitly by default. This
allows us to drop `_LIBCPP_HIDE_FROM_ABI` in most of the code base,
except for functions which shouldn't be `_LIBCPP_HIDE_FROM_ABI`.
This patch doesn't remove any `_LIBCPP_HIDE_FROM_ABI`s, since we have
over 13k of them in the code base. Actually dropping them will happen
over some time to avoid too many merge conflicts.
Our own `fenv.h` only `#undef`s macros which the C header might define.
None of the libcs we support define any of these functions as macros, so
we can simply drop the header.
Our own `ctype.h` only `#undef`s macros which the C header might define.
None of the libcs we support define any of these functions as macros, so
we can simply drop the header.
The header does three things:
- it defines `__STDC_FORMAT_MACROS` for compatibility with glibc
versions we don't support anymore
- it includes `<stdint.h>`, which is already required to be included by
the C standard
- it `#undef`s two macros which might be defined by the libc. We don't
provide a `<stdint.h>` header ourselves, which might provide these
macros as well, so these are already not defined by any libcs we
support.
So this header should be safe to remove.
This PR allows libc++ to be configured to use LLVM-libc without
requiring locale-variants of libc functions.
This PR updates libc++ to use `<llvm-libc-types/mbstate_t.h>`
when building against LLVM-libc to avoid pulling in all of `wchar.h`.
There is some code duplication in this PR. The code in `formatting.h` is
similar to the implementation in `fuchsia.h`, except that the new code
does not use thread-local locales via `__locale_guard`:
673002f325/libcxx/include/__locale_dir/support/fuchsia.h (L133)
If reviewers would like, I'm happy to refactor to create more shared
headers, similar to how `no_locale` is set up. I've avoided doing so in
this PR, but lmk. It looks like there's three general ways these
passthrough functions are defined for unix systems:
- No locale (e.g. Fuchsia's `strtod` ignores locales entirely).
- Thread-local locale (e.g. other Fuchsia functions use `__locale_guard`
set up locales via `uselocale`).
- Native locale-specific function variant (i.e. the proxy just uses the
*_l variant, like `toupper_l`).
Implement `ranges::stride_view` in libc++. This PR was migrated from
Phabricator (https://reviews.llvm.org/D156924).
Closes#105198
Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
Co-authored-by: A. Jiang <de34@live.cn>
This is another step in splitting up `<__config>` to make it easier to
understand what's going on and have logically separate parts of the
configuration properly separated.
`formatter::parse` and `formatter::format` only have to accept
`basic_format_parse_context` and `basic_format_context` respectively,
which are only guaranteed to be provided via `<format>`. This allows us
to only declare the functions for `formatter<bool>` in `<vector>` and
define them if `<format>` is included. This reduces the amount of time
it takes to parse `<vector>` by ~15% on my system.
Create a new `__capacity_aware_iterator` iterator type which wraps an
existing iterator, takes its container as a template parameter, and
encodes the maximum amount of elements the container can hold. The main
objective is to prevent iterator mixups between different containers
(e.g. `vector`).
This patch moves all macros which expand to attributes into a detail
header, including the relatively complex visibility and ABI-hiding
attributes. This also adds sections for attributes that are important to
not be ignored. At the bottom there is a catch-all section for
attributes which can safely be ignored and are only important for the
quality of implementation.
The existence of <float.h> in libc++ leads to difficulties with modules,
especially when it comes to supporting the various __need macros
supported by the Clang builtin headers.
Fortunately, libc++'s <float.h> only defines FLT_EVAL_METHOD and
DECIMAL_DIG, which are already defined by the Clang builtin headers in
C++11 mode. Hence, removing the header entirely should have no impact,
apart from not defining FLT_EVAL_METHOD and DECIMAL_DIG in C++03 mode.
However, that is arguably something that libc++ shouldn't be doing: if
the underlying C library doesn't want to provide these definitions, then
libc++ shouldn't force it to.
#175913 removed that `__builtin_assume_dereferenceable(ptr, 0)` implies
`ptr != nullptr`, which should allow us to use the builtin with LLVM 23.
This reverts commit 776c09c212.
`__builtin_assume_dereferenceable` currently implies that the pointer
given to it is non-null, even if the size is zero. This causes
miscompilations, since we consider [nullptr, nullptr) to be a valid
range.
Reverts llvm/llvm-project#167697
It makes sense to decouple traits from the things they describe, since
that's the purpose of traits. Furthermore, this will make it possible to
reuse these traits from other places in the library (e.g. <semaphore>)
outside of the synchronization library.
Pre-C++20 support is removed as a drive-by since the synchronization
library does not support pre-C++20 anymore. This makes it possible to
simplify a few constructs by using concepts.
Requested in https://github.com/llvm/llvm-project/pull/172214#discussion_r2635968291
This implements all of [P2404R3](https://wg21.link/p2404r3)'s concept
changes.
---------
Co-authored-by: A. Jiang <de34@live.cn>
Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
## Introduction
This patch implements `ranges::elements_of` from
[P2502R2](https://wg21.link/P2502R2). Specializations of `elements_of`
encapsulate a range and act as a tag in overload sets to disambiguate
when a range should be treated as a sequence rather than a single value.
```cpp
template <bool YieldElements>
std::generator<std::any> f(std::ranges::input_range auto &&r) {
if constexpr (YieldElements) {
co_yield std::ranges::elements_of(r);
} else {
co_yield r;
}
}
```
## Reference
- [P2502R2: `std::generator`: Synchronous Coroutine Generator for
Ranges](https://wg21.link/P2502R2)
- [[range.elementsof]](https://eel.is/c++draft/range.elementsof)
Partially addresses #105226
---------
Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
Co-authored-by: A. Jiang <de34@live.cn>
`[[nodiscard]]` should be applied to functions where discarding the
return value is most likely a correctness issue.
- https://libcxx.llvm.org/CodingGuidelines.html
1. `hash<shared_ptr>`, `hash<unique_ptr>`, `std::integer_sequence<>`
etc.
2. Also implements fixes to
https://github.com/llvm/llvm-project/issues/169634 on the go (issues
discovered during current implementation)
---------
Co-authored-by: A. Jiang <de34@live.cn>
Co-authored-by: Hristo Hristov <zingam@outlook.com>
Tested on Newlib v4.5.0. The newlib.h was mostly copied from linux.h
within the same directory.
Newlib locale support was initially added in http://llvm.org/D5385,
but removed in #113721 , because of revision http://llvm.org/D49927.