[libcxx-commits] [libcxx] [libcxx] adds a size-based representation for `vector`'s unstable ABI (PR #155330)
Christopher Di Bella via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Jan 28 11:00:04 PST 2026
================
@@ -577,25 +609,127 @@ class vector {
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI bool __invariants() const;
+#ifdef _LIBCPP_ABI_SIZE_BASED_VECTOR
+
private:
+ using __sentinel_type _LIBCPP_NODEBUG = size_type;
+
+ [[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI size_type __raw_sentinel() const _NOEXCEPT {
+ return __size_;
+ }
+
+ [[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI pointer __end_pointer() const _NOEXCEPT {
+ return __begin_ + __size_;
+ }
+
+ [[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI size_type
+ __remaining_capacity() const _NOEXCEPT {
+ return __cap_ - __size_;
+ }
+
+ [[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI bool __is_full() const _NOEXCEPT {
+ return __size_ == __cap_;
+ }
+
+ _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __set_valid_range(pointer __begin, pointer __end) _NOEXCEPT {
+ __begin_ = __begin;
+ __size_ = __end - __begin_;
+ }
+
+ _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
+ __set_valid_range(pointer __begin, size_type __size) _NOEXCEPT {
+ __begin_ = __begin;
+ __size_ = __size;
+ }
+
+ _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __set_sentinel(size_type __size) _NOEXCEPT {
+ __size_ = __size;
+ }
+
+ _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __set_sentinel(pointer __pos) _NOEXCEPT {
+ __size_ = static_cast<size_type>(__pos - __begin_);
+ }
+
+ _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __set_capacity(size_type __cap) _NOEXCEPT { __cap_ = __cap; }
+
+ _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __set_capacity(pointer __pos) _NOEXCEPT {
+ __cap_ = static_cast<size_type>(__pos - __begin_);
+ }
+
+ pointer __begin_ = nullptr;
----------------
cjdb wrote:
I've compared 980deac7e0a20302b7d6b7c00f86bdb6427f8ee7 (PR HEAD~12) and bd4de75da409b19a199e1f2052a70e219b16bf3e (yours), and I think they're very similar, so I should be able to revert to 980deac7e0a20302b7d6b7c00f86bdb6427f8ee7 without much difficulty. I'm going to integrate as many of the differences from bd4de75da409b19a199e1f2052a70e219b16bf3e into my next revision (e.g. moving the layouts into `__vector/layout.h` was a nice suggestion!).
Pushing the next commit is blocked on a concern regarding one of the larger differences. Here's a really abstract version of bd4de75da409b19a199e1f2052a70e219b16bf3e:
```diff
template<class _T, class _Alloc>
class vector {
// ...
- pointer __begin_;
- pointer __end_;
- _LIBCPP_COMPRESSED_PAIR(pointer, __cap_ = nullptr, allocator_type, __alloc_);
+ __layout_t __layout_;
+ [[no_unique_address]] _Alloc __alloc_;
};
```
My understanding is that this is ABI-breaking because we're replacing the compressed pair with something that's always `[[no_unique_address]]`. Is this understanding still correct, and if so, is it a break we're willing to carry forward? Most other incompatibilities are resolvable in a round of reviews, but this one seriously affects how much code I end up pushing.
https://github.com/llvm/llvm-project/pull/155330
More information about the libcxx-commits
mailing list