From 8270bffc375d652f19b28eca9be7ae0c78cdce05 Mon Sep 17 00:00:00 2001 From: kboyarinov Date: Thu, 8 Dec 2022 08:18:51 -0600 Subject: [PATCH 01/26] Remove version namespace for memory_resource --- libcxx/include/__config | 2 + libcxx/include/__fwd/memory_resource.h | 4 +- libcxx/include/__fwd/string.h | 11 ++- .../__memory_resource/memory_resource.h | 5 +- .../monotonic_buffer_resource.h | 4 +- .../__memory_resource/polymorphic_allocator.h | 52 +--------- .../include/__memory_resource/pool_options.h | 4 +- .../synchronized_pool_resource.h | 4 +- .../unsynchronized_pool_resource.h | 4 +- libcxx/include/deque | 8 +- libcxx/include/experimental/deque | 2 +- libcxx/include/experimental/forward_list | 2 +- libcxx/include/experimental/list | 2 +- libcxx/include/experimental/map | 4 +- libcxx/include/forward_list | 8 +- libcxx/include/list | 8 +- libcxx/include/map | 10 +- libcxx/include/regex | 8 +- libcxx/include/set | 10 +- libcxx/include/unordered_map | 10 +- libcxx/include/unordered_set | 10 +- libcxx/include/vector | 95 +++++-------------- libcxx/src/memory_resource.cpp | 4 +- 23 files changed, 84 insertions(+), 187 deletions(-) diff --git a/libcxx/include/__config b/libcxx/include/__config index b80e4cb4ee5ed..3fbf00dfb87a0 100644 --- a/libcxx/include/__config +++ b/libcxx/include/__config @@ -633,7 +633,9 @@ typedef __char32_t char32_t; // Inline namespaces are available in Clang/GCC/MSVC regardless of C++ dialect. // clang-format off # define _LIBCPP_BEGIN_NAMESPACE_STD namespace std { inline namespace _LIBCPP_ABI_NAMESPACE { +# define _LIBCPP_BEGIN_NAMESPACE_STD_PMR namespace std { namespace pmr { inline namespace _LIBCPP_ABI_NAMESPACE { # define _LIBCPP_END_NAMESPACE_STD }} +# define _LIBCPP_END_NAMESPACE_STD_PMR }}} # define _VSTD std _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD diff --git a/libcxx/include/__fwd/memory_resource.h b/libcxx/include/__fwd/memory_resource.h index 718a9078d3cfb..a8f71e5270dbd 100644 --- a/libcxx/include/__fwd/memory_resource.h +++ b/libcxx/include/__fwd/memory_resource.h @@ -15,13 +15,13 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD +namespace std { // purposefully not using versioning namespace namespace pmr { template class _LIBCPP_TEMPLATE_VIS polymorphic_allocator; } // namespace pmr -_LIBCPP_END_NAMESPACE_STD +} #endif // _LIBCPP___FWD_MEMORY_RESOURCE_H diff --git a/libcxx/include/__fwd/string.h b/libcxx/include/__fwd/string.h index 7ab5561b758f2..a4ad4807ab574 100644 --- a/libcxx/include/__fwd/string.h +++ b/libcxx/include/__fwd/string.h @@ -59,9 +59,13 @@ using u32string = basic_string; #if _LIBCPP_STD_VER >= 17 -namespace pmr { +_LIBCPP_END_NAMESPACE_STD +_LIBCPP_BEGIN_NAMESPACE_STD_PMR + +using ___alloc = std::pmr::polymorphic_allocator; + template > -using basic_string = std::basic_string<_CharT, _Traits, polymorphic_allocator<_CharT>>; +using basic_string = std::basic_string<_CharT, _Traits, std::pmr::polymorphic_allocator<_CharT>>; using string = basic_string; @@ -76,7 +80,8 @@ using u8string = basic_string; using u16string = basic_string; using u32string = basic_string; -} // namespace pmr +_LIBCPP_END_NAMESPACE_STD_PMR +_LIBCPP_BEGIN_NAMESPACE_STD #endif // _LIBCPP_STD_VER >= 17 diff --git a/libcxx/include/__memory_resource/memory_resource.h b/libcxx/include/__memory_resource/memory_resource.h index 02fdd081cce5f..cedf53d15f13e 100644 --- a/libcxx/include/__memory_resource/memory_resource.h +++ b/libcxx/include/__memory_resource/memory_resource.h @@ -18,7 +18,8 @@ #if _LIBCPP_STD_VER > 14 -_LIBCPP_BEGIN_NAMESPACE_STD +namespace std // purposefully not using versioning namespace +{ namespace pmr { @@ -68,7 +69,7 @@ inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const memory_resource& __lhs, const } // namespace pmr -_LIBCPP_END_NAMESPACE_STD +} // namespace std #endif // _LIBCPP_STD_VER > 14 diff --git a/libcxx/include/__memory_resource/monotonic_buffer_resource.h b/libcxx/include/__memory_resource/monotonic_buffer_resource.h index 5c35a62b1663c..3fa7473bfc5cd 100644 --- a/libcxx/include/__memory_resource/monotonic_buffer_resource.h +++ b/libcxx/include/__memory_resource/monotonic_buffer_resource.h @@ -20,7 +20,7 @@ #if _LIBCPP_STD_VER > 14 -_LIBCPP_BEGIN_NAMESPACE_STD +namespace std { // purposefully not using versioning namespace namespace pmr { @@ -112,7 +112,7 @@ class _LIBCPP_TYPE_VIS monotonic_buffer_resource : public memory_resource { } // namespace pmr -_LIBCPP_END_NAMESPACE_STD +} #endif // _LIBCPP_STD_VER > 14 diff --git a/libcxx/include/__memory_resource/polymorphic_allocator.h b/libcxx/include/__memory_resource/polymorphic_allocator.h index 8e59dfc55d78c..2c69b33ed338b 100644 --- a/libcxx/include/__memory_resource/polymorphic_allocator.h +++ b/libcxx/include/__memory_resource/polymorphic_allocator.h @@ -12,7 +12,6 @@ #include <__assert> #include <__config> #include <__memory_resource/memory_resource.h> -#include <__utility/transaction.h> #include #include #include @@ -28,19 +27,14 @@ _LIBCPP_PUSH_MACROS #if _LIBCPP_STD_VER > 14 -_LIBCPP_BEGIN_NAMESPACE_STD +namespace std { // purposefully not using versioning namespace namespace pmr { // [mem.poly.allocator.class] -template = 20 - = byte -# endif - > +template class _LIBCPP_TEMPLATE_VIS polymorphic_allocator { - public: using value_type = _ValueType; @@ -72,46 +66,6 @@ class _LIBCPP_TEMPLATE_VIS polymorphic_allocator { __res_->deallocate(__p, __n * sizeof(_ValueType), alignof(_ValueType)); } -# if _LIBCPP_STD_VER >= 20 - - [[nodiscard]] [[using __gnu__: __alloc_size__(2), __alloc_align__(3)]] void* - allocate_bytes(size_t __nbytes, size_t __alignment = alignof(max_align_t)) { - return __res_->allocate(__nbytes, __alignment); - } - - void deallocate_bytes(void* __ptr, size_t __nbytes, size_t __alignment = alignof(max_align_t)) { - __res_->deallocate(__ptr, __nbytes, __alignment); - } - - template - [[nodiscard]] _Type* allocate_object(size_t __n = 1) { - if (numeric_limits::max() / sizeof(_Type) < __n) - std::__throw_bad_array_new_length(); - return static_cast<_Type*>(allocate_bytes(__n * sizeof(_Type), alignof(_Type))); - } - - template - void deallocate_object(_Type* __ptr, size_t __n = 1) { - deallocate_bytes(__ptr, __n * sizeof(_Type), alignof(_Type)); - } - - template - [[nodiscard]] _Type* new_object(_CtorArgs&&... __ctor_args) { - _Type* __ptr = allocate_object<_Type>(); - __transaction __guard([&] { deallocate_object(__ptr); }); - construct(__ptr, std::forward<_CtorArgs>(__ctor_args)...); - __guard.__complete(); - return __ptr; - } - - template - void delete_object(_Type* __ptr) { - destroy(__ptr); - deallocate_object(__ptr); - } - -# endif // _LIBCPP_STD_VER >= 20 - template _LIBCPP_HIDE_FROM_ABI void construct(_Tp* __p, _Ts&&... __args) { std::__user_alloc_construct_impl( @@ -215,7 +169,7 @@ operator!=(const polymorphic_allocator<_Tp>& __lhs, const polymorphic_allocator< } // namespace pmr -_LIBCPP_END_NAMESPACE_STD +} #endif // _LIBCPP_STD_VER > 14 diff --git a/libcxx/include/__memory_resource/pool_options.h b/libcxx/include/__memory_resource/pool_options.h index 11585a0e3bc87..60cebc4c0d844 100644 --- a/libcxx/include/__memory_resource/pool_options.h +++ b/libcxx/include/__memory_resource/pool_options.h @@ -18,7 +18,7 @@ #if _LIBCPP_STD_VER > 14 -_LIBCPP_BEGIN_NAMESPACE_STD +namespace std { // purposefully not using versioning namespace namespace pmr { @@ -31,7 +31,7 @@ struct _LIBCPP_TYPE_VIS pool_options { } // namespace pmr -_LIBCPP_END_NAMESPACE_STD +} #endif // _LIBCPP_STD_VER > 14 diff --git a/libcxx/include/__memory_resource/synchronized_pool_resource.h b/libcxx/include/__memory_resource/synchronized_pool_resource.h index 550223c7d9689..18b53f79f713e 100644 --- a/libcxx/include/__memory_resource/synchronized_pool_resource.h +++ b/libcxx/include/__memory_resource/synchronized_pool_resource.h @@ -24,7 +24,7 @@ #if _LIBCPP_STD_VER > 14 -_LIBCPP_BEGIN_NAMESPACE_STD +namespace std { // purposefully not using versioning namespace namespace pmr { @@ -87,7 +87,7 @@ class _LIBCPP_TYPE_VIS synchronized_pool_resource : public memory_resource { } // namespace pmr -_LIBCPP_END_NAMESPACE_STD +} #endif // _LIBCPP_STD_VER > 14 diff --git a/libcxx/include/__memory_resource/unsynchronized_pool_resource.h b/libcxx/include/__memory_resource/unsynchronized_pool_resource.h index 7270cf19e214a..281f053d076ef 100644 --- a/libcxx/include/__memory_resource/unsynchronized_pool_resource.h +++ b/libcxx/include/__memory_resource/unsynchronized_pool_resource.h @@ -21,7 +21,7 @@ #if _LIBCPP_STD_VER > 14 -_LIBCPP_BEGIN_NAMESPACE_STD +namespace std { // purposefully not using versioning namespace namespace pmr { @@ -99,7 +99,7 @@ class _LIBCPP_TYPE_VIS unsynchronized_pool_resource : public memory_resource { } // namespace pmr -_LIBCPP_END_NAMESPACE_STD +} #endif // _LIBCPP_STD_VER > 14 diff --git a/libcxx/include/deque b/libcxx/include/deque index 989b64d7a109e..ae6d6f4c15c83 100644 --- a/libcxx/include/deque +++ b/libcxx/include/deque @@ -2932,12 +2932,10 @@ inline constexpr bool __format::__enable_insertable> = true; _LIBCPP_END_NAMESPACE_STD #if _LIBCPP_STD_VER > 14 -_LIBCPP_BEGIN_NAMESPACE_STD -namespace pmr { +_LIBCPP_BEGIN_NAMESPACE_STD_PMR template -using deque = std::deque<_ValueT, polymorphic_allocator<_ValueT>>; -} // namespace pmr -_LIBCPP_END_NAMESPACE_STD +using deque = std::deque<_ValueT, std::pmr::polymorphic_allocator<_ValueT>>; +_LIBCPP_END_NAMESPACE_STD_PMR #endif _LIBCPP_POP_MACROS diff --git a/libcxx/include/experimental/deque b/libcxx/include/experimental/deque index 46962afbb795e..430b31d7447dd 100644 --- a/libcxx/include/experimental/deque +++ b/libcxx/include/experimental/deque @@ -43,7 +43,7 @@ _LIBCPP_BEGIN_NAMESPACE_LFTS_PMR #ifndef _LIBCPP_CXX03_LANG template -using deque = _VSTD::deque<_ValueT, polymorphic_allocator<_ValueT>>; +using deque = _VSTD::deque<_ValueT, std::pmr::polymorphic_allocator<_ValueT>>; #endif // _LIBCPP_CXX03_LANG diff --git a/libcxx/include/experimental/forward_list b/libcxx/include/experimental/forward_list index 5d2686deb2768..59886d7eb458e 100644 --- a/libcxx/include/experimental/forward_list +++ b/libcxx/include/experimental/forward_list @@ -43,7 +43,7 @@ _LIBCPP_BEGIN_NAMESPACE_LFTS_PMR #ifndef _LIBCPP_CXX03_LANG template -using forward_list = _VSTD::forward_list<_ValueT, polymorphic_allocator<_ValueT>>; +using forward_list = _VSTD::forward_list<_ValueT, std::pmr::polymorphic_allocator<_ValueT>>; #endif // _LIBCPP_CXX03_LANG diff --git a/libcxx/include/experimental/list b/libcxx/include/experimental/list index 06abe8702241e..62d7f59e95a67 100644 --- a/libcxx/include/experimental/list +++ b/libcxx/include/experimental/list @@ -43,7 +43,7 @@ _LIBCPP_BEGIN_NAMESPACE_LFTS_PMR #ifndef _LIBCPP_CXX03_LANG template -using list = _VSTD::list<_ValueT, polymorphic_allocator<_ValueT>>; +using list = _VSTD::list<_ValueT, std::pmr::polymorphic_allocator<_ValueT>>; #endif // _LIBCPP_CXX03_LANG diff --git a/libcxx/include/experimental/map b/libcxx/include/experimental/map index 8ec94e4a5bc86..5730562801519 100644 --- a/libcxx/include/experimental/map +++ b/libcxx/include/experimental/map @@ -49,11 +49,11 @@ _LIBCPP_BEGIN_NAMESPACE_LFTS_PMR template > using map = _VSTD::map<_Key, _Value, _Compare, - polymorphic_allocator>>; + std::pmr::polymorphic_allocator>>; template > using multimap = _VSTD::multimap<_Key, _Value, _Compare, - polymorphic_allocator>>; + std::pmr::polymorphic_allocator>>; #endif // _LIBCPP_CXX03_LANG diff --git a/libcxx/include/forward_list b/libcxx/include/forward_list index 61dde8167dfcd..d3ae6073d44b8 100644 --- a/libcxx/include/forward_list +++ b/libcxx/include/forward_list @@ -1780,12 +1780,10 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_END_NAMESPACE_STD #if _LIBCPP_STD_VER > 14 -_LIBCPP_BEGIN_NAMESPACE_STD -namespace pmr { +_LIBCPP_BEGIN_NAMESPACE_STD_PMR template -using forward_list = std::forward_list<_ValueT, polymorphic_allocator<_ValueT>>; -} // namespace pmr -_LIBCPP_END_NAMESPACE_STD +using forward_list = std::forward_list<_ValueT, std::pmr::polymorphic_allocator<_ValueT>>; +_LIBCPP_END_NAMESPACE_STD_PMR #endif _LIBCPP_POP_MACROS diff --git a/libcxx/include/list b/libcxx/include/list index a0c732739ca28..c25c24aa551b5 100644 --- a/libcxx/include/list +++ b/libcxx/include/list @@ -2363,12 +2363,10 @@ inline constexpr bool __format::__enable_insertable> = true; _LIBCPP_END_NAMESPACE_STD #if _LIBCPP_STD_VER > 14 -_LIBCPP_BEGIN_NAMESPACE_STD -namespace pmr { +_LIBCPP_BEGIN_NAMESPACE_STD_PMR template -using list = std::list<_ValueT, polymorphic_allocator<_ValueT>>; -} // namespace pmr -_LIBCPP_END_NAMESPACE_STD +using list = std::list<_ValueT, std::pmr::polymorphic_allocator<_ValueT>>; +_LIBCPP_END_NAMESPACE_STD_PMR #endif _LIBCPP_POP_MACROS diff --git a/libcxx/include/map b/libcxx/include/map index 9cf47b245a02a..580693e58c68d 100644 --- a/libcxx/include/map +++ b/libcxx/include/map @@ -2340,15 +2340,13 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_END_NAMESPACE_STD #if _LIBCPP_STD_VER > 14 -_LIBCPP_BEGIN_NAMESPACE_STD -namespace pmr { +_LIBCPP_BEGIN_NAMESPACE_STD_PMR template > -using map = std::map<_KeyT, _ValueT, _CompareT, polymorphic_allocator>>; +using map = std::map<_KeyT, _ValueT, _CompareT, std::pmr::polymorphic_allocator>>; template > -using multimap = std::multimap<_KeyT, _ValueT, _CompareT, polymorphic_allocator>>; -} // namespace pmr -_LIBCPP_END_NAMESPACE_STD +using multimap = std::multimap<_KeyT, _ValueT, _CompareT, std::pmr::polymorphic_allocator>>; +_LIBCPP_END_NAMESPACE_STD_PMR #endif #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 diff --git a/libcxx/include/regex b/libcxx/include/regex index f35197339ba9c..e728edefdb744 100644 --- a/libcxx/include/regex +++ b/libcxx/include/regex @@ -6845,10 +6845,9 @@ regex_replace(const _CharT* __s, _LIBCPP_END_NAMESPACE_STD #if _LIBCPP_STD_VER > 14 -_LIBCPP_BEGIN_NAMESPACE_STD -namespace pmr { +_LIBCPP_BEGIN_NAMESPACE_STD_PMR template -using match_results = std::match_results<_BidirT, polymorphic_allocator>>; +using match_results = std::match_results<_BidirT, std::pmr::polymorphic_allocator>>; using cmatch = match_results; using smatch = match_results; @@ -6857,8 +6856,7 @@ using smatch = match_results; using wcmatch = match_results; using wsmatch = match_results; #endif -} // namespace pmr -_LIBCPP_END_NAMESPACE_STD +_LIBCPP_END_NAMESPACE_STD_PMR #endif _LIBCPP_POP_MACROS diff --git a/libcxx/include/set b/libcxx/include/set index 1154c4e9509c7..fa95560a3d4ed 100644 --- a/libcxx/include/set +++ b/libcxx/include/set @@ -1585,15 +1585,13 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_END_NAMESPACE_STD #if _LIBCPP_STD_VER > 14 -_LIBCPP_BEGIN_NAMESPACE_STD -namespace pmr { +_LIBCPP_BEGIN_NAMESPACE_STD_PMR template > -using set = std::set<_KeyT, _CompareT, polymorphic_allocator<_KeyT>>; +using set = std::set<_KeyT, _CompareT, std::pmr::polymorphic_allocator<_KeyT>>; template > -using multiset = std::multiset<_KeyT, _CompareT, polymorphic_allocator<_KeyT>>; -} // namespace pmr -_LIBCPP_END_NAMESPACE_STD +using multiset = std::multiset<_KeyT, _CompareT, std::pmr::polymorphic_allocator<_KeyT>>; +_LIBCPP_END_NAMESPACE_STD_PMR #endif #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 diff --git a/libcxx/include/unordered_map b/libcxx/include/unordered_map index cd0aea1205d52..a7f9a1a6b9e89 100644 --- a/libcxx/include/unordered_map +++ b/libcxx/include/unordered_map @@ -2630,17 +2630,15 @@ operator!=(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, _LIBCPP_END_NAMESPACE_STD #if _LIBCPP_STD_VER > 14 -_LIBCPP_BEGIN_NAMESPACE_STD -namespace pmr { +_LIBCPP_BEGIN_NAMESPACE_STD_PMR template , class _PredT = std::equal_to<_KeyT>> using unordered_map = - std::unordered_map<_KeyT, _ValueT, _HashT, _PredT, polymorphic_allocator>>; + std::unordered_map<_KeyT, _ValueT, _HashT, _PredT, std::pmr::polymorphic_allocator>>; template , class _PredT = std::equal_to<_KeyT>> using unordered_multimap = - std::unordered_multimap<_KeyT, _ValueT, _HashT, _PredT, polymorphic_allocator>>; -} // namespace pmr -_LIBCPP_END_NAMESPACE_STD + std::unordered_multimap<_KeyT, _ValueT, _HashT, _PredT, std::pmr::polymorphic_allocator>>; +_LIBCPP_END_NAMESPACE_STD_PMR #endif #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 diff --git a/libcxx/include/unordered_set b/libcxx/include/unordered_set index 9a25510139428..4bf600d292a11 100644 --- a/libcxx/include/unordered_set +++ b/libcxx/include/unordered_set @@ -1804,15 +1804,13 @@ operator!=(const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x, _LIBCPP_END_NAMESPACE_STD #if _LIBCPP_STD_VER > 14 -_LIBCPP_BEGIN_NAMESPACE_STD -namespace pmr { +_LIBCPP_BEGIN_NAMESPACE_STD_PMR template , class _PredT = std::equal_to<_KeyT>> -using unordered_set = std::unordered_set<_KeyT, _HashT, _PredT, polymorphic_allocator<_KeyT>>; +using unordered_set = std::unordered_set<_KeyT, _HashT, _PredT, std::pmr::polymorphic_allocator<_KeyT>>; template , class _PredT = std::equal_to<_KeyT>> -using unordered_multiset = std::unordered_multiset<_KeyT, _HashT, _PredT, polymorphic_allocator<_KeyT>>; -} // namespace pmr -_LIBCPP_END_NAMESPACE_STD +using unordered_multiset = std::unordered_multiset<_KeyT, _HashT, _PredT, std::pmr::polymorphic_allocator<_KeyT>>; +_LIBCPP_END_NAMESPACE_STD_PMR #endif #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 diff --git a/libcxx/include/vector b/libcxx/include/vector index bbf92145aa10d..f595a5cd74f12 100644 --- a/libcxx/include/vector +++ b/libcxx/include/vector @@ -302,7 +302,6 @@ erase_if(vector& c, Predicate pred); // C++20 #include <__utility/forward.h> #include <__utility/move.h> #include <__utility/swap.h> -#include <__utility/transaction.h> #include #include #include @@ -424,27 +423,18 @@ public: _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a); -private: - class __destroy_vector { - public: - _LIBCPP_CONSTEXPR __destroy_vector(vector& __vec) : __vec_(__vec) {} - - _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void operator()() { - __vec_.__annotate_delete(); - std::__debug_db_erase_c(std::addressof(__vec_)); + _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI + ~vector() + { + __annotate_delete(); + std::__debug_db_erase_c(this); - if (__vec_.__begin_ != nullptr) { - __vec_.__clear(); - __alloc_traits::deallocate(__vec_.__alloc(), __vec_.__begin_, __vec_.capacity()); - } + if (this->__begin_ != nullptr) + { + __clear(); + __alloc_traits::deallocate(__alloc(), this->__begin_, capacity()); } - - private: - vector& __vec_; - }; - -public: - _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI ~vector() { __destroy_vector(*this)(); } + } _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(const vector& __x); _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(const vector& __x, const __type_identity_t& __a); @@ -1064,14 +1054,12 @@ template _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(size_type __n) { - auto __guard = std::__make_transaction(__destroy_vector(*this)); std::__debug_db_insert_c(this); if (__n > 0) { __vallocate(__n); __construct_at_end(__n); } - __guard.__complete(); } #if _LIBCPP_STD_VER > 11 @@ -1080,14 +1068,12 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(size_type __n, const allocator_type& __a) : __end_cap_(nullptr, __a) { - auto __guard = std::__make_transaction(__destroy_vector(*this)); std::__debug_db_insert_c(this); if (__n > 0) { __vallocate(__n); __construct_at_end(__n); } - __guard.__complete(); } #endif @@ -1095,14 +1081,12 @@ template _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(size_type __n, const value_type& __x) { - auto __guard = std::__make_transaction(__destroy_vector(*this)); std::__debug_db_insert_c(this); if (__n > 0) { __vallocate(__n); __construct_at_end(__n, __x); } - __guard.__complete(); } template @@ -1112,11 +1096,9 @@ template ::vector(_InputIterator __first, _InputIterator __last) { - auto __guard = std::__make_transaction(__destroy_vector(*this)); std::__debug_db_insert_c(this); for (; __first != __last; ++__first) emplace_back(*__first); - __guard.__complete(); } template @@ -1127,11 +1109,9 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a) : __end_cap_(nullptr, __a) { - auto __guard = std::__make_transaction(__destroy_vector(*this)); std::__debug_db_insert_c(this); for (; __first != __last; ++__first) emplace_back(*__first); - __guard.__complete(); } template @@ -1141,7 +1121,6 @@ template ::vector(_ForwardIterator __first, _ForwardIterator __last) { - auto __guard = std::__make_transaction(__destroy_vector(*this)); std::__debug_db_insert_c(this); size_type __n = static_cast(std::distance(__first, __last)); if (__n > 0) @@ -1149,7 +1128,6 @@ vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __las __vallocate(__n); __construct_at_end(__first, __last, __n); } - __guard.__complete(); } template @@ -1160,7 +1138,6 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a) : __end_cap_(nullptr, __a) { - auto __guard = std::__make_transaction(__destroy_vector(*this)); std::__debug_db_insert_c(this); size_type __n = static_cast(std::distance(__first, __last)); if (__n > 0) @@ -1168,7 +1145,6 @@ vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __las __vallocate(__n); __construct_at_end(__first, __last, __n); } - __guard.__complete(); } template @@ -1176,7 +1152,6 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(const vector& __x) : __end_cap_(nullptr, __alloc_traits::select_on_container_copy_construction(__x.__alloc())) { - auto __guard = std::__make_transaction(__destroy_vector(*this)); std::__debug_db_insert_c(this); size_type __n = __x.size(); if (__n > 0) @@ -1184,7 +1159,6 @@ vector<_Tp, _Allocator>::vector(const vector& __x) __vallocate(__n); __construct_at_end(__x.__begin_, __x.__end_, __n); } - __guard.__complete(); } template @@ -1192,7 +1166,6 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(const vector& __x, const __type_identity_t& __a) : __end_cap_(nullptr, __a) { - auto __guard = std::__make_transaction(__destroy_vector(*this)); std::__debug_db_insert_c(this); size_type __n = __x.size(); if (__n > 0) @@ -1200,7 +1173,6 @@ vector<_Tp, _Allocator>::vector(const vector& __x, const __type_identity_t @@ -1240,9 +1212,7 @@ vector<_Tp, _Allocator>::vector(vector&& __x, const __type_identity_t _Ip; - auto __guard = std::__make_transaction(__destroy_vector(*this)); assign(_Ip(__x.begin()), _Ip(__x.end())); - __guard.__complete(); } } @@ -1253,14 +1223,12 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI vector<_Tp, _Allocator>::vector(initializer_list __il) { - auto __guard = std::__make_transaction(__destroy_vector(*this)); std::__debug_db_insert_c(this); if (__il.size() > 0) { __vallocate(__il.size()); __construct_at_end(__il.begin(), __il.end(), __il.size()); } - __guard.__complete(); } template @@ -1269,14 +1237,12 @@ inline _LIBCPP_HIDE_FROM_ABI vector<_Tp, _Allocator>::vector(initializer_list __il, const allocator_type& __a) : __end_cap_(nullptr, __a) { - auto __guard = std::__make_transaction(__destroy_vector(*this)); std::__debug_db_insert_c(this); if (__il.size() > 0) { __vallocate(__il.size()); __construct_at_end(__il.begin(), __il.end(), __il.size()); } - __guard.__complete(); } #endif // _LIBCPP_CXX03_LANG @@ -2094,25 +2060,7 @@ public: #else _NOEXCEPT; #endif - -private: - class __destroy_vector { - public: - _LIBCPP_CONSTEXPR __destroy_vector(vector& __vec) : __vec_(__vec) {} - - _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void operator()() { - if (__vec_.__begin_ != nullptr) - __storage_traits::deallocate(__vec_.__alloc(), __vec_.__begin_, __vec_.__cap()); - std::__debug_db_invalidate_all(this); - } - - private: - vector& __vec_; - }; - -public: - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 ~vector() { __destroy_vector(*this)(); } - + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 ~vector(); _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit vector(size_type __n); #if _LIBCPP_STD_VER > 11 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit vector(size_type __n, const allocator_type& __a); @@ -2648,14 +2596,12 @@ vector::vector(_ForwardIterator __first, _ForwardIterator __la __size_(0), __cap_alloc_(0, __default_init_tag()) { - auto __guard = std::__make_transaction(__destroy_vector(*this)); size_type __n = static_cast(std::distance(__first, __last)); if (__n > 0) { __vallocate(__n); __construct_at_end(__first, __last); } - __guard.__complete(); } template @@ -2667,14 +2613,12 @@ vector::vector(_ForwardIterator __first, _ForwardIterator __la __size_(0), __cap_alloc_(0, static_cast<__storage_allocator>(__a)) { - auto __guard = std::__make_transaction(__destroy_vector(*this)); size_type __n = static_cast(std::distance(__first, __last)); if (__n > 0) { __vallocate(__n); __construct_at_end(__first, __last); } - __guard.__complete(); } #ifndef _LIBCPP_CXX03_LANG @@ -2711,6 +2655,15 @@ vector::vector(initializer_list __il, const alloca #endif // _LIBCPP_CXX03_LANG +template +_LIBCPP_CONSTEXPR_SINCE_CXX20 +vector::~vector() +{ + if (__begin_ != nullptr) + __storage_traits::deallocate(__alloc(), __begin_, __cap()); + std::__debug_db_invalidate_all(this); +} + template _LIBCPP_CONSTEXPR_SINCE_CXX20 vector::vector(const vector& __v) @@ -3315,12 +3268,10 @@ inline constexpr bool __format::__enable_insertable> = true _LIBCPP_END_NAMESPACE_STD #if _LIBCPP_STD_VER > 14 -_LIBCPP_BEGIN_NAMESPACE_STD -namespace pmr { +_LIBCPP_BEGIN_NAMESPACE_STD_PMR template -using vector = std::vector<_ValueT, polymorphic_allocator<_ValueT>>; -} // namespace pmr -_LIBCPP_END_NAMESPACE_STD +using vector = std::vector<_ValueT, std::pmr::polymorphic_allocator<_ValueT>>; +_LIBCPP_END_NAMESPACE_STD_PMR #endif _LIBCPP_POP_MACROS diff --git a/libcxx/src/memory_resource.cpp b/libcxx/src/memory_resource.cpp index d4a735b4232c6..7daba159ecf74 100644 --- a/libcxx/src/memory_resource.cpp +++ b/libcxx/src/memory_resource.cpp @@ -18,7 +18,7 @@ # endif #endif -_LIBCPP_BEGIN_NAMESPACE_STD +namespace std { namespace pmr { @@ -476,4 +476,4 @@ void* monotonic_buffer_resource::do_allocate(size_t bytes, size_t align) { } // namespace pmr -_LIBCPP_END_NAMESPACE_STD +} From ffe580590096702452c6e07d170561eb9a6114ea Mon Sep 17 00:00:00 2001 From: tbbdev Date: Sun, 18 Dec 2022 17:28:47 +0200 Subject: [PATCH 02/26] Add Microsoft STL compat layer --- libcxx/src/memory_resource.cpp | 112 +--------------- .../runtime/default_resource_fallback.ipp | 121 ++++++++++++++++++ .../support/runtime/default_resource_msvc.ipp | 64 +++++++++ 3 files changed, 191 insertions(+), 106 deletions(-) create mode 100644 libcxx/src/support/runtime/default_resource_fallback.ipp create mode 100644 libcxx/src/support/runtime/default_resource_msvc.ipp diff --git a/libcxx/src/memory_resource.cpp b/libcxx/src/memory_resource.cpp index 7daba159ecf74..6d0f723056ba9 100644 --- a/libcxx/src/memory_resource.cpp +++ b/libcxx/src/memory_resource.cpp @@ -9,6 +9,12 @@ #include #include +#if defined(_LIBCPP_ABI_MICROSOFT) +# include "support/runtime/default_resource_msvc.ipp" +#else +# include "support/runtime/default_resource_fallback.ipp" +#endif + #ifndef _LIBCPP_HAS_NO_ATOMIC_HEADER # include #elif !defined(_LIBCPP_HAS_NO_THREADS) @@ -26,112 +32,6 @@ namespace pmr { memory_resource::~memory_resource() = default; -// new_delete_resource() - -#ifdef _LIBCPP_HAS_NO_ALIGNED_ALLOCATION -static bool is_aligned_to(void* ptr, size_t align) { - void* p2 = ptr; - size_t space = 1; - void* result = std::align(align, 1, p2, space); - return (result == ptr); -} -#endif - -class _LIBCPP_TYPE_VIS __new_delete_memory_resource_imp : public memory_resource { - void* do_allocate(size_t bytes, size_t align) override { -#ifndef _LIBCPP_HAS_NO_ALIGNED_ALLOCATION - return std::__libcpp_allocate(bytes, align); -#else - if (bytes == 0) - bytes = 1; - void* result = std::__libcpp_allocate(bytes, align); - if (!is_aligned_to(result, align)) { - std::__libcpp_deallocate(result, bytes, align); - __throw_bad_alloc(); - } - return result; -#endif - } - - void do_deallocate(void* p, size_t bytes, size_t align) override { std::__libcpp_deallocate(p, bytes, align); } - - bool do_is_equal(const memory_resource& other) const noexcept override { return &other == this; } -}; - -// null_memory_resource() - -class _LIBCPP_TYPE_VIS __null_memory_resource_imp : public memory_resource { - void* do_allocate(size_t, size_t) override { __throw_bad_alloc(); } - void do_deallocate(void*, size_t, size_t) override {} - bool do_is_equal(const memory_resource& other) const noexcept override { return &other == this; } -}; - -namespace { - -union ResourceInitHelper { - struct { - __new_delete_memory_resource_imp new_delete_res; - __null_memory_resource_imp null_res; - } resources; - char dummy; - _LIBCPP_CONSTEXPR_SINCE_CXX14 ResourceInitHelper() : resources() {} - ~ResourceInitHelper() {} -}; - -// Pretend we're inside a system header so the compiler doesn't flag the use of the init_priority -// attribute with a value that's reserved for the implementation (we're the implementation). -#include "memory_resource_init_helper.h" - -} // end namespace - -memory_resource* new_delete_resource() noexcept { return &res_init.resources.new_delete_res; } - -memory_resource* null_memory_resource() noexcept { return &res_init.resources.null_res; } - -// default_memory_resource() - -static memory_resource* __default_memory_resource(bool set = false, memory_resource* new_res = nullptr) noexcept { -#ifndef _LIBCPP_HAS_NO_ATOMIC_HEADER - static constinit atomic __res{&res_init.resources.new_delete_res}; - if (set) { - new_res = new_res ? new_res : new_delete_resource(); - // TODO: Can a weaker ordering be used? - return std::atomic_exchange_explicit(&__res, new_res, memory_order_acq_rel); - } else { - return std::atomic_load_explicit(&__res, memory_order_acquire); - } -#elif !defined(_LIBCPP_HAS_NO_THREADS) - static constinit memory_resource* res = &res_init.resources.new_delete_res; - static mutex res_lock; - if (set) { - new_res = new_res ? new_res : new_delete_resource(); - lock_guard guard(res_lock); - memory_resource* old_res = res; - res = new_res; - return old_res; - } else { - lock_guard guard(res_lock); - return res; - } -#else - static constinit memory_resource* res = &res_init.resources.new_delete_res; - if (set) { - new_res = new_res ? new_res : new_delete_resource(); - memory_resource* old_res = res; - res = new_res; - return old_res; - } else { - return res; - } -#endif -} - -memory_resource* get_default_resource() noexcept { return __default_memory_resource(); } - -memory_resource* set_default_resource(memory_resource* __new_res) noexcept { - return __default_memory_resource(true, __new_res); -} - // 23.12.5, mem.res.pool static size_t roundup(size_t count, size_t alignment) { diff --git a/libcxx/src/support/runtime/default_resource_fallback.ipp b/libcxx/src/support/runtime/default_resource_fallback.ipp new file mode 100644 index 0000000000000..b700acf5f8113 --- /dev/null +++ b/libcxx/src/support/runtime/default_resource_fallback.ipp @@ -0,0 +1,121 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +namespace std { + +namespace pmr { + +// default_memory_resource() + +static memory_resource* __default_memory_resource(bool set = false, memory_resource* new_res = nullptr) noexcept { +#ifndef _LIBCPP_HAS_NO_ATOMIC_HEADER + static constinit atomic __res{&res_init.resources.new_delete_res}; + if (set) { + new_res = new_res ? new_res : new_delete_resource(); + // TODO: Can a weaker ordering be used? + return std::atomic_exchange_explicit(&__res, new_res, memory_order_acq_rel); + } else { + return std::atomic_load_explicit(&__res, memory_order_acquire); + } +#elif !defined(_LIBCPP_HAS_NO_THREADS) + static constinit memory_resource* res = &res_init.resources.new_delete_res; + static mutex res_lock; + if (set) { + new_res = new_res ? new_res : new_delete_resource(); + lock_guard guard(res_lock); + memory_resource* old_res = res; + res = new_res; + return old_res; + } else { + lock_guard guard(res_lock); + return res; + } +#else + static constinit memory_resource* res = &res_init.resources.new_delete_res; + if (set) { + new_res = new_res ? new_res : new_delete_resource(); + memory_resource* old_res = res; + res = new_res; + return old_res; + } else { + return res; + } +#endif +} + +memory_resource* get_default_resource() noexcept { return __default_memory_resource(); } + +memory_resource* set_default_resource(memory_resource* __new_res) noexcept { + return __default_memory_resource(true, __new_res); +} + +// new_delete_resource() + +#ifdef _LIBCPP_HAS_NO_ALIGNED_ALLOCATION +static bool is_aligned_to(void* ptr, size_t align) { + void* p2 = ptr; + size_t space = 1; + void* result = std::align(align, 1, p2, space); + return (result == ptr); +} +#endif + +class _LIBCPP_TYPE_VIS __new_delete_memory_resource_imp : public memory_resource { + void* do_allocate(size_t bytes, size_t align) override { +#ifndef _LIBCPP_HAS_NO_ALIGNED_ALLOCATION + return std::__libcpp_allocate(bytes, align); +#else + if (bytes == 0) + bytes = 1; + void* result = std::__libcpp_allocate(bytes, align); + if (!is_aligned_to(result, align)) { + std::__libcpp_deallocate(result, bytes, align); + __throw_bad_alloc(); + } + return result; +#endif + } + + void do_deallocate(void* p, size_t bytes, size_t align) override { std::__libcpp_deallocate(p, bytes, align); } + + bool do_is_equal(const memory_resource& other) const noexcept override { return &other == this; } +}; + +// null_memory_resource() + +class _LIBCPP_TYPE_VIS __null_memory_resource_imp : public memory_resource { + void* do_allocate(size_t, size_t) override { __throw_bad_alloc(); } + void do_deallocate(void*, size_t, size_t) override {} + bool do_is_equal(const memory_resource& other) const noexcept override { return &other == this; } +}; + +namespace { + +union ResourceInitHelper { + struct { + __new_delete_memory_resource_imp new_delete_res; + __null_memory_resource_imp null_res; + } resources; + char dummy; + _LIBCPP_CONSTEXPR_SINCE_CXX14 ResourceInitHelper() : resources() {} + ~ResourceInitHelper() {} +}; + +// Pretend we're inside a system header so the compiler doesn't flag the use of the init_priority +// attribute with a value that's reserved for the implementation (we're the implementation). +#include "memory_resource_init_helper.h" + +} // end namespace + +memory_resource* new_delete_resource() noexcept { return &res_init.resources.new_delete_res; } + +memory_resource* null_memory_resource() noexcept { return &res_init.resources.null_res; } + +} // pmr +} // std diff --git a/libcxx/src/support/runtime/default_resource_msvc.ipp b/libcxx/src/support/runtime/default_resource_msvc.ipp new file mode 100644 index 0000000000000..b7e041aa3adc3 --- /dev/null +++ b/libcxx/src/support/runtime/default_resource_msvc.ipp @@ -0,0 +1,64 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_ABI_MICROSOFT +#error this header can only be used when targeting the MSVC ABI +#endif + +// default_memory_resource() + +extern "C" { + +_LIBCPP_CRT_FUNC std::pmr::memory_resource* __cdecl _Aligned_set_default_resource(std::pmr::memory_resource*) noexcept; +_LIBCPP_CRT_FUNC std::pmr::memory_resource* __cdecl _Unaligned_set_default_resource(std::pmr::memory_resource*) noexcept; +_LIBCPP_CRT_FUNC std::pmr::memory_resource* __cdecl _Aligned_get_default_resource() noexcept; +_LIBCPP_CRT_FUNC std::pmr::memory_resource* __cdecl _Unaligned_get_default_resource() noexcept; +_LIBCPP_CRT_FUNC std::pmr::memory_resource* __cdecl _Aligned_new_delete_resource() noexcept; +_LIBCPP_CRT_FUNC std::pmr::memory_resource* __cdecl _Unaligned_new_delete_resource() noexcept; +_LIBCPP_CRT_FUNC std::pmr::memory_resource* __cdecl null_memory_resource() noexcept; + +}; + +namespace std { + +namespace pmr { + +memory_resource* get_default_resource() noexcept { + printf("Debug: compat get_default_resouce\n"); +#ifdef __cpp_aligned_new + return ::_Aligned_get_default_resource(); +#else + return ::_Unaligned_get_default_resource(); +#endif +} + +memory_resource* set_default_resource(memory_resource* __new_res) noexcept { + printf("Debug: compat set_default_resouce\n"); +#ifdef __cpp_aligned_new + return ::_Aligned_set_default_resource(__new_res); +#else + return ::_Unaligned_set_default_resource(__new_res); +#endif +} + +memory_resource* new_delete_resource() noexcept { +#ifdef __cpp_aligned_new + return ::_Aligned_new_delete_resource(); +#else + return ::_Unaligned_new_delete_resource(); +#endif +} + +memory_resource* null_memory_resource() noexcept { + return ::null_memory_resource(); +} + +} // pmr + +} // std From a1f139378f00099c8b415bbd40cf2fdc3e7d0832 Mon Sep 17 00:00:00 2001 From: tbbdev Date: Sun, 18 Dec 2022 17:40:35 +0200 Subject: [PATCH 03/26] Remove unnecessary things --- libcxx/include/__fwd/string.h | 2 - .../__memory_resource/polymorphic_allocator.h | 47 +++++- libcxx/include/vector | 134 +++++++++--------- libcxx/src/memory_resource.cpp | 2 +- .../runtime/default_resource_fallback.ipp | 4 +- .../support/runtime/default_resource_msvc.ipp | 4 +- 6 files changed, 121 insertions(+), 72 deletions(-) diff --git a/libcxx/include/__fwd/string.h b/libcxx/include/__fwd/string.h index a4ad4807ab574..6393d4430ad90 100644 --- a/libcxx/include/__fwd/string.h +++ b/libcxx/include/__fwd/string.h @@ -62,8 +62,6 @@ using u32string = basic_string; _LIBCPP_END_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD_PMR -using ___alloc = std::pmr::polymorphic_allocator; - template > using basic_string = std::basic_string<_CharT, _Traits, std::pmr::polymorphic_allocator<_CharT>>; diff --git a/libcxx/include/__memory_resource/polymorphic_allocator.h b/libcxx/include/__memory_resource/polymorphic_allocator.h index 2c69b33ed338b..c22b3b053192d 100644 --- a/libcxx/include/__memory_resource/polymorphic_allocator.h +++ b/libcxx/include/__memory_resource/polymorphic_allocator.h @@ -33,8 +33,13 @@ namespace pmr { // [mem.poly.allocator.class] -template +template = 20 + = byte +# endif + > class _LIBCPP_TEMPLATE_VIS polymorphic_allocator { + public: using value_type = _ValueType; @@ -66,6 +71,46 @@ class _LIBCPP_TEMPLATE_VIS polymorphic_allocator { __res_->deallocate(__p, __n * sizeof(_ValueType), alignof(_ValueType)); } +# if _LIBCPP_STD_VER >= 20 + + [[nodiscard]] [[using __gnu__: __alloc_size__(2), __alloc_align__(3)]] void* + allocate_bytes(size_t __nbytes, size_t __alignment = alignof(max_align_t)) { + return __res_->allocate(__nbytes, __alignment); + } + + void deallocate_bytes(void* __ptr, size_t __nbytes, size_t __alignment = alignof(max_align_t)) { + __res_->deallocate(__ptr, __nbytes, __alignment); + } + + template + [[nodiscard]] _Type* allocate_object(size_t __n = 1) { + if (numeric_limits::max() / sizeof(_Type) < __n) + std::__throw_bad_array_new_length(); + return static_cast<_Type*>(allocate_bytes(__n * sizeof(_Type), alignof(_Type))); + } + + template + void deallocate_object(_Type* __ptr, size_t __n = 1) { + deallocate_bytes(__ptr, __n * sizeof(_Type), alignof(_Type)); + } + + template + [[nodiscard]] _Type* new_object(_CtorArgs&&... __ctor_args) { + _Type* __ptr = allocate_object<_Type>(); + __transaction __guard([&] { deallocate_object(__ptr); }); + construct(__ptr, std::forward<_CtorArgs>(__ctor_args)...); + __guard.__complete(); + return __ptr; + } + + template + void delete_object(_Type* __ptr) { + destroy(__ptr); + deallocate_object(__ptr); + } + +# endif // _LIBCPP_STD_VER >= 20 + template _LIBCPP_HIDE_FROM_ABI void construct(_Tp* __p, _Ts&&... __args) { std::__user_alloc_construct_impl( diff --git a/libcxx/include/vector b/libcxx/include/vector index f595a5cd74f12..33f36e208f0ca 100644 --- a/libcxx/include/vector +++ b/libcxx/include/vector @@ -12,10 +12,8 @@ /* vector synopsis - namespace std { - template > class vector { @@ -32,7 +30,6 @@ public: typedef typename allocator_type::const_pointer const_pointer; typedef std::reverse_iterator reverse_iterator; typedef std::reverse_iterator const_reverse_iterator; - vector() noexcept(is_nothrow_default_constructible::value); explicit vector(const allocator_type&); @@ -57,50 +54,40 @@ public: void assign(InputIterator first, InputIterator last); void assign(size_type n, const value_type& u); void assign(initializer_list il); - allocator_type get_allocator() const noexcept; - iterator begin() noexcept; const_iterator begin() const noexcept; iterator end() noexcept; const_iterator end() const noexcept; - reverse_iterator rbegin() noexcept; const_reverse_iterator rbegin() const noexcept; reverse_iterator rend() noexcept; const_reverse_iterator rend() const noexcept; - const_iterator cbegin() const noexcept; const_iterator cend() const noexcept; const_reverse_iterator crbegin() const noexcept; const_reverse_iterator crend() const noexcept; - size_type size() const noexcept; size_type max_size() const noexcept; size_type capacity() const noexcept; bool empty() const noexcept; void reserve(size_type n); void shrink_to_fit() noexcept; - reference operator[](size_type n); const_reference operator[](size_type n) const; reference at(size_type n); const_reference at(size_type n) const; - reference front(); const_reference front() const; reference back(); const_reference back() const; - value_type* data() noexcept; const value_type* data() const noexcept; - void push_back(const value_type& x); void push_back(value_type&& x); template reference emplace_back(Args&&... args); // reference in C++17 void pop_back(); - template iterator emplace(const_iterator position, Args&&... args); iterator insert(const_iterator position, const value_type& x); iterator insert(const_iterator position, value_type&& x); @@ -108,22 +95,16 @@ public: template iterator insert(const_iterator position, InputIterator first, InputIterator last); iterator insert(const_iterator position, initializer_list il); - iterator erase(const_iterator position); iterator erase(const_iterator first, const_iterator last); - void clear() noexcept; - void resize(size_type sz); void resize(size_type sz, const value_type& c); - void swap(vector&) noexcept(allocator_traits::propagate_on_container_swap::value || allocator_traits::is_always_equal::value); // C++17 - bool __invariants() const; }; - template > class vector { @@ -138,7 +119,6 @@ public: typedef const_iterator const_pointer; typedef std::reverse_iterator reverse_iterator; typedef std::reverse_iterator const_reverse_iterator; - class reference { public: @@ -149,7 +129,6 @@ public: iterator operator&() const noexcept; void flip() noexcept; }; - class const_reference { public: @@ -157,7 +136,6 @@ public: operator bool() const noexcept; const_iterator operator&() const noexcept; }; - vector() noexcept(is_nothrow_default_constructible::value); explicit vector(const allocator_type&); @@ -181,94 +159,73 @@ public: void assign(InputIterator first, InputIterator last); void assign(size_type n, const value_type& u); void assign(initializer_list il); - allocator_type get_allocator() const noexcept; - iterator begin() noexcept; const_iterator begin() const noexcept; iterator end() noexcept; const_iterator end() const noexcept; - reverse_iterator rbegin() noexcept; const_reverse_iterator rbegin() const noexcept; reverse_iterator rend() noexcept; const_reverse_iterator rend() const noexcept; - const_iterator cbegin() const noexcept; const_iterator cend() const noexcept; const_reverse_iterator crbegin() const noexcept; const_reverse_iterator crend() const noexcept; - size_type size() const noexcept; size_type max_size() const noexcept; size_type capacity() const noexcept; bool empty() const noexcept; void reserve(size_type n); void shrink_to_fit() noexcept; - reference operator[](size_type n); const_reference operator[](size_type n) const; reference at(size_type n); const_reference at(size_type n) const; - reference front(); const_reference front() const; reference back(); const_reference back() const; - void push_back(const value_type& x); template reference emplace_back(Args&&... args); // C++14; reference in C++17 void pop_back(); - template iterator emplace(const_iterator position, Args&&... args); // C++14 iterator insert(const_iterator position, const value_type& x); iterator insert(const_iterator position, size_type n, const value_type& x); template iterator insert(const_iterator position, InputIterator first, InputIterator last); iterator insert(const_iterator position, initializer_list il); - iterator erase(const_iterator position); iterator erase(const_iterator first, const_iterator last); - void clear() noexcept; - void resize(size_type sz); void resize(size_type sz, value_type x); - void swap(vector&) noexcept(allocator_traits::propagate_on_container_swap::value || allocator_traits::is_always_equal::value); // C++17 void flip() noexcept; - bool __invariants() const; }; - template ::value_type>> vector(InputIterator, InputIterator, Allocator = Allocator()) -> vector::value_type, Allocator>; // C++17 - template struct hash>; - template bool operator==(const vector& x, const vector& y); template bool operator< (const vector& x, const vector& y); template bool operator!=(const vector& x, const vector& y); template bool operator> (const vector& x, const vector& y); template bool operator>=(const vector& x, const vector& y); template bool operator<=(const vector& x, const vector& y); - template void swap(vector& x, vector& y) noexcept(noexcept(x.swap(y))); - template typename vector::size_type erase(vector& c, const U& value); // C++20 template typename vector::size_type erase_if(vector& c, Predicate pred); // C++20 - } // std - */ #include <__algorithm/copy.h> @@ -302,6 +259,7 @@ erase_if(vector& c, Predicate pred); // C++20 #include <__utility/forward.h> #include <__utility/move.h> #include <__utility/swap.h> +#include <__utility/transaction.h> #include #include #include @@ -423,18 +381,27 @@ public: _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a); - _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI - ~vector() - { - __annotate_delete(); - std::__debug_db_erase_c(this); +private: + class __destroy_vector { + public: + _LIBCPP_CONSTEXPR __destroy_vector(vector& __vec) : __vec_(__vec) {} - if (this->__begin_ != nullptr) - { - __clear(); - __alloc_traits::deallocate(__alloc(), this->__begin_, capacity()); + _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void operator()() { + __vec_.__annotate_delete(); + std::__debug_db_erase_c(std::addressof(__vec_)); + + if (__vec_.__begin_ != nullptr) { + __vec_.__clear(); + __alloc_traits::deallocate(__vec_.__alloc(), __vec_.__begin_, __vec_.capacity()); + } } - } + + private: + vector& __vec_; + }; + +public: + _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI ~vector() { __destroy_vector(*this)(); } _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(const vector& __x); _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(const vector& __x, const __type_identity_t& __a); @@ -1054,12 +1021,14 @@ template _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(size_type __n) { + auto __guard = std::__make_transaction(__destroy_vector(*this)); std::__debug_db_insert_c(this); if (__n > 0) { __vallocate(__n); __construct_at_end(__n); } + __guard.__complete(); } #if _LIBCPP_STD_VER > 11 @@ -1068,12 +1037,14 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(size_type __n, const allocator_type& __a) : __end_cap_(nullptr, __a) { + auto __guard = std::__make_transaction(__destroy_vector(*this)); std::__debug_db_insert_c(this); if (__n > 0) { __vallocate(__n); __construct_at_end(__n); } + __guard.__complete(); } #endif @@ -1081,12 +1052,14 @@ template _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(size_type __n, const value_type& __x) { + auto __guard = std::__make_transaction(__destroy_vector(*this)); std::__debug_db_insert_c(this); if (__n > 0) { __vallocate(__n); __construct_at_end(__n, __x); } + __guard.__complete(); } template @@ -1096,9 +1069,11 @@ template ::vector(_InputIterator __first, _InputIterator __last) { + auto __guard = std::__make_transaction(__destroy_vector(*this)); std::__debug_db_insert_c(this); for (; __first != __last; ++__first) emplace_back(*__first); + __guard.__complete(); } template @@ -1109,9 +1084,11 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a) : __end_cap_(nullptr, __a) { + auto __guard = std::__make_transaction(__destroy_vector(*this)); std::__debug_db_insert_c(this); for (; __first != __last; ++__first) emplace_back(*__first); + __guard.__complete(); } template @@ -1121,6 +1098,7 @@ template ::vector(_ForwardIterator __first, _ForwardIterator __last) { + auto __guard = std::__make_transaction(__destroy_vector(*this)); std::__debug_db_insert_c(this); size_type __n = static_cast(std::distance(__first, __last)); if (__n > 0) @@ -1128,6 +1106,7 @@ vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __las __vallocate(__n); __construct_at_end(__first, __last, __n); } + __guard.__complete(); } template @@ -1138,6 +1117,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a) : __end_cap_(nullptr, __a) { + auto __guard = std::__make_transaction(__destroy_vector(*this)); std::__debug_db_insert_c(this); size_type __n = static_cast(std::distance(__first, __last)); if (__n > 0) @@ -1145,6 +1125,7 @@ vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __las __vallocate(__n); __construct_at_end(__first, __last, __n); } + __guard.__complete(); } template @@ -1152,6 +1133,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(const vector& __x) : __end_cap_(nullptr, __alloc_traits::select_on_container_copy_construction(__x.__alloc())) { + auto __guard = std::__make_transaction(__destroy_vector(*this)); std::__debug_db_insert_c(this); size_type __n = __x.size(); if (__n > 0) @@ -1159,6 +1141,7 @@ vector<_Tp, _Allocator>::vector(const vector& __x) __vallocate(__n); __construct_at_end(__x.__begin_, __x.__end_, __n); } + __guard.__complete(); } template @@ -1166,6 +1149,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(const vector& __x, const __type_identity_t& __a) : __end_cap_(nullptr, __a) { + auto __guard = std::__make_transaction(__destroy_vector(*this)); std::__debug_db_insert_c(this); size_type __n = __x.size(); if (__n > 0) @@ -1173,6 +1157,7 @@ vector<_Tp, _Allocator>::vector(const vector& __x, const __type_identity_t @@ -1212,7 +1197,9 @@ vector<_Tp, _Allocator>::vector(vector&& __x, const __type_identity_t _Ip; + auto __guard = std::__make_transaction(__destroy_vector(*this)); assign(_Ip(__x.begin()), _Ip(__x.end())); + __guard.__complete(); } } @@ -1223,12 +1210,14 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI vector<_Tp, _Allocator>::vector(initializer_list __il) { + auto __guard = std::__make_transaction(__destroy_vector(*this)); std::__debug_db_insert_c(this); if (__il.size() > 0) { __vallocate(__il.size()); __construct_at_end(__il.begin(), __il.end(), __il.size()); } + __guard.__complete(); } template @@ -1237,12 +1226,14 @@ inline _LIBCPP_HIDE_FROM_ABI vector<_Tp, _Allocator>::vector(initializer_list __il, const allocator_type& __a) : __end_cap_(nullptr, __a) { + auto __guard = std::__make_transaction(__destroy_vector(*this)); std::__debug_db_insert_c(this); if (__il.size() > 0) { __vallocate(__il.size()); __construct_at_end(__il.begin(), __il.end(), __il.size()); } + __guard.__complete(); } #endif // _LIBCPP_CXX03_LANG @@ -2060,7 +2051,25 @@ public: #else _NOEXCEPT; #endif - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 ~vector(); + +private: + class __destroy_vector { + public: + _LIBCPP_CONSTEXPR __destroy_vector(vector& __vec) : __vec_(__vec) {} + + _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void operator()() { + if (__vec_.__begin_ != nullptr) + __storage_traits::deallocate(__vec_.__alloc(), __vec_.__begin_, __vec_.__cap()); + std::__debug_db_invalidate_all(this); + } + + private: + vector& __vec_; + }; + +public: + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 ~vector() { __destroy_vector(*this)(); } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit vector(size_type __n); #if _LIBCPP_STD_VER > 11 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit vector(size_type __n, const allocator_type& __a); @@ -2596,12 +2605,14 @@ vector::vector(_ForwardIterator __first, _ForwardIterator __la __size_(0), __cap_alloc_(0, __default_init_tag()) { + auto __guard = std::__make_transaction(__destroy_vector(*this)); size_type __n = static_cast(std::distance(__first, __last)); if (__n > 0) { __vallocate(__n); __construct_at_end(__first, __last); } + __guard.__complete(); } template @@ -2613,12 +2624,14 @@ vector::vector(_ForwardIterator __first, _ForwardIterator __la __size_(0), __cap_alloc_(0, static_cast<__storage_allocator>(__a)) { + auto __guard = std::__make_transaction(__destroy_vector(*this)); size_type __n = static_cast(std::distance(__first, __last)); if (__n > 0) { __vallocate(__n); __construct_at_end(__first, __last); } + __guard.__complete(); } #ifndef _LIBCPP_CXX03_LANG @@ -2655,15 +2668,6 @@ vector::vector(initializer_list __il, const alloca #endif // _LIBCPP_CXX03_LANG -template -_LIBCPP_CONSTEXPR_SINCE_CXX20 -vector::~vector() -{ - if (__begin_ != nullptr) - __storage_traits::deallocate(__alloc(), __begin_, __cap()); - std::__debug_db_invalidate_all(this); -} - template _LIBCPP_CONSTEXPR_SINCE_CXX20 vector::vector(const vector& __v) @@ -3269,8 +3273,10 @@ _LIBCPP_END_NAMESPACE_STD #if _LIBCPP_STD_VER > 14 _LIBCPP_BEGIN_NAMESPACE_STD_PMR +namespace pmr { template using vector = std::vector<_ValueT, std::pmr::polymorphic_allocator<_ValueT>>; +} // namespace pmr _LIBCPP_END_NAMESPACE_STD_PMR #endif @@ -3284,4 +3290,4 @@ _LIBCPP_POP_MACROS # include #endif -#endif // _LIBCPP_VECTOR +#endif // _LIBCPP_VECTOR \ No newline at end of file diff --git a/libcxx/src/memory_resource.cpp b/libcxx/src/memory_resource.cpp index 6d0f723056ba9..aca46ff6c7504 100644 --- a/libcxx/src/memory_resource.cpp +++ b/libcxx/src/memory_resource.cpp @@ -376,4 +376,4 @@ void* monotonic_buffer_resource::do_allocate(size_t bytes, size_t align) { } // namespace pmr -} +} // namespace std diff --git a/libcxx/src/support/runtime/default_resource_fallback.ipp b/libcxx/src/support/runtime/default_resource_fallback.ipp index b700acf5f8113..9685c498b20c7 100644 --- a/libcxx/src/support/runtime/default_resource_fallback.ipp +++ b/libcxx/src/support/runtime/default_resource_fallback.ipp @@ -117,5 +117,5 @@ memory_resource* new_delete_resource() noexcept { return &res_init.resources.new memory_resource* null_memory_resource() noexcept { return &res_init.resources.null_res; } -} // pmr -} // std +} // namespace pmr +} // namespace std diff --git a/libcxx/src/support/runtime/default_resource_msvc.ipp b/libcxx/src/support/runtime/default_resource_msvc.ipp index b7e041aa3adc3..96b25434deef4 100644 --- a/libcxx/src/support/runtime/default_resource_msvc.ipp +++ b/libcxx/src/support/runtime/default_resource_msvc.ipp @@ -59,6 +59,6 @@ memory_resource* null_memory_resource() noexcept { return ::null_memory_resource(); } -} // pmr +} // namespace pmr -} // std +} // namespace std From 8a76ddfa03583a7c46b316e2ee83020993ab616a Mon Sep 17 00:00:00 2001 From: tbbdev Date: Sun, 18 Dec 2022 17:43:55 +0200 Subject: [PATCH 04/26] +newline --- libcxx/include/vector | 2 +- libcxx/src/{ => support/runtime}/memory_resource_init_helper.h | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename libcxx/src/{ => support/runtime}/memory_resource_init_helper.h (100%) diff --git a/libcxx/include/vector b/libcxx/include/vector index 33f36e208f0ca..d1277b94e0f64 100644 --- a/libcxx/include/vector +++ b/libcxx/include/vector @@ -3290,4 +3290,4 @@ _LIBCPP_POP_MACROS # include #endif -#endif // _LIBCPP_VECTOR \ No newline at end of file +#endif // _LIBCPP_VECTOR diff --git a/libcxx/src/memory_resource_init_helper.h b/libcxx/src/support/runtime/memory_resource_init_helper.h similarity index 100% rename from libcxx/src/memory_resource_init_helper.h rename to libcxx/src/support/runtime/memory_resource_init_helper.h From bf5b96259c351637d505832deaca8cad9b2a4c03 Mon Sep 17 00:00:00 2001 From: tbbdev Date: Sun, 18 Dec 2022 17:44:57 +0200 Subject: [PATCH 05/26] Whitespace fix --- libcxx/src/memory_resource.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libcxx/src/memory_resource.cpp b/libcxx/src/memory_resource.cpp index aca46ff6c7504..8ac49a0f47706 100644 --- a/libcxx/src/memory_resource.cpp +++ b/libcxx/src/memory_resource.cpp @@ -10,9 +10,9 @@ #include #if defined(_LIBCPP_ABI_MICROSOFT) -# include "support/runtime/default_resource_msvc.ipp" +# include "support/runtime/default_resource_msvc.ipp" #else -# include "support/runtime/default_resource_fallback.ipp" +# include "support/runtime/default_resource_fallback.ipp" #endif #ifndef _LIBCPP_HAS_NO_ATOMIC_HEADER From 1f44aad23aac8adc79ea652d6ea011e7ec6ea5ce Mon Sep 17 00:00:00 2001 From: tbbdev Date: Sun, 18 Dec 2022 18:43:42 +0200 Subject: [PATCH 06/26] Rename compat layer files --- libcxx/src/memory_resource.cpp | 4 ++-- ...ult_resource_fallback.ipp => memory_resource_fallback.ipp} | 0 .../{default_resource_msvc.ipp => memory_resource_msvc.ipp} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename libcxx/src/support/runtime/{default_resource_fallback.ipp => memory_resource_fallback.ipp} (100%) rename libcxx/src/support/runtime/{default_resource_msvc.ipp => memory_resource_msvc.ipp} (100%) diff --git a/libcxx/src/memory_resource.cpp b/libcxx/src/memory_resource.cpp index 8ac49a0f47706..8ce0ad4d3894b 100644 --- a/libcxx/src/memory_resource.cpp +++ b/libcxx/src/memory_resource.cpp @@ -10,9 +10,9 @@ #include #if defined(_LIBCPP_ABI_MICROSOFT) -# include "support/runtime/default_resource_msvc.ipp" +# include "support/runtime/memory_resource_msvc.ipp" #else -# include "support/runtime/default_resource_fallback.ipp" +# include "support/runtime/memory_resource_fallback.ipp" #endif #ifndef _LIBCPP_HAS_NO_ATOMIC_HEADER diff --git a/libcxx/src/support/runtime/default_resource_fallback.ipp b/libcxx/src/support/runtime/memory_resource_fallback.ipp similarity index 100% rename from libcxx/src/support/runtime/default_resource_fallback.ipp rename to libcxx/src/support/runtime/memory_resource_fallback.ipp diff --git a/libcxx/src/support/runtime/default_resource_msvc.ipp b/libcxx/src/support/runtime/memory_resource_msvc.ipp similarity index 100% rename from libcxx/src/support/runtime/default_resource_msvc.ipp rename to libcxx/src/support/runtime/memory_resource_msvc.ipp From 8bb59cf43cb378fee167e2ea1b9e92a7a48a6998 Mon Sep 17 00:00:00 2001 From: kboyarinov Date: Thu, 22 Dec 2022 09:51:20 -0600 Subject: [PATCH 07/26] Broken: remove unnecessary macros from config --- libcxx/include/__config | 2 -- 1 file changed, 2 deletions(-) diff --git a/libcxx/include/__config b/libcxx/include/__config index 3fbf00dfb87a0..b80e4cb4ee5ed 100644 --- a/libcxx/include/__config +++ b/libcxx/include/__config @@ -633,9 +633,7 @@ typedef __char32_t char32_t; // Inline namespaces are available in Clang/GCC/MSVC regardless of C++ dialect. // clang-format off # define _LIBCPP_BEGIN_NAMESPACE_STD namespace std { inline namespace _LIBCPP_ABI_NAMESPACE { -# define _LIBCPP_BEGIN_NAMESPACE_STD_PMR namespace std { namespace pmr { inline namespace _LIBCPP_ABI_NAMESPACE { # define _LIBCPP_END_NAMESPACE_STD }} -# define _LIBCPP_END_NAMESPACE_STD_PMR }}} # define _VSTD std _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD From 378272c754d21317df65d5234a50922b4097d234 Mon Sep 17 00:00:00 2001 From: kboyarinov Date: Thu, 22 Dec 2022 09:59:05 -0600 Subject: [PATCH 08/26] Broken: minor fixes in __fwd --- libcxx/include/__fwd/memory_resource.h | 2 +- libcxx/include/__fwd/string.h | 53 +++++++++++++------------- 2 files changed, 28 insertions(+), 27 deletions(-) diff --git a/libcxx/include/__fwd/memory_resource.h b/libcxx/include/__fwd/memory_resource.h index a8f71e5270dbd..b6c85d8d69d30 100644 --- a/libcxx/include/__fwd/memory_resource.h +++ b/libcxx/include/__fwd/memory_resource.h @@ -22,6 +22,6 @@ template class _LIBCPP_TEMPLATE_VIS polymorphic_allocator; } // namespace pmr -} +} // namespace std #endif // _LIBCPP___FWD_MEMORY_RESOURCE_H diff --git a/libcxx/include/__fwd/string.h b/libcxx/include/__fwd/string.h index 6393d4430ad90..234b7767e0497 100644 --- a/libcxx/include/__fwd/string.h +++ b/libcxx/include/__fwd/string.h @@ -57,32 +57,6 @@ using u8string = basic_string; using u16string = basic_string; using u32string = basic_string; -#if _LIBCPP_STD_VER >= 17 - -_LIBCPP_END_NAMESPACE_STD -_LIBCPP_BEGIN_NAMESPACE_STD_PMR - -template > -using basic_string = std::basic_string<_CharT, _Traits, std::pmr::polymorphic_allocator<_CharT>>; - -using string = basic_string; - -# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS -using wstring = basic_string; -# endif - -# ifndef _LIBCPP_HAS_NO_CHAR8_T -using u8string = basic_string; -# endif - -using u16string = basic_string; -using u32string = basic_string; - -_LIBCPP_END_NAMESPACE_STD_PMR -_LIBCPP_BEGIN_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 17 - // clang-format off template class _LIBCPP_PREFERRED_NAME(string) @@ -110,4 +84,31 @@ class _LIBCPP_PREFERRED_NAME(string) _LIBCPP_END_NAMESPACE_STD +#if _LIBCPP_STD_VER >= 17 + +namespace std { +namespace pmr { + +template > +using basic_string = std::basic_string<_CharT, _Traits, std::pmr::polymorphic_allocator<_CharT>>; + +using string = basic_string; + +# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +using wstring = basic_string; +# endif + +# ifndef _LIBCPP_HAS_NO_CHAR8_T +using u8string = basic_string; +# endif + +using u16string = basic_string; +using u32string = basic_string; + +} // namespace pmr + +} // namespace std + +#endif // _LIBCPP_STD_VER >= 17 + #endif // _LIBCPP___FWD_STRING_H From 4ddf19cee7fac40d50d8e1866c27e5193b8b914f Mon Sep 17 00:00:00 2001 From: kboyarinov Date: Thu, 22 Dec 2022 10:49:22 -0600 Subject: [PATCH 09/26] Working: minor cosmetic changes --- libcxx/include/__fwd/memory_resource.h | 2 +- libcxx/include/__fwd/string.h | 2 +- libcxx/include/__memory_resource/memory_resource.h | 3 +-- .../__memory_resource/monotonic_buffer_resource.h | 4 ++-- .../__memory_resource/polymorphic_allocator.h | 5 +++-- libcxx/include/__memory_resource/pool_options.h | 4 ++-- .../__memory_resource/synchronized_pool_resource.h | 4 ++-- .../unsynchronized_pool_resource.h | 4 ++-- libcxx/include/deque | 13 ++++++++++--- libcxx/include/experimental/deque | 2 +- libcxx/include/experimental/forward_list | 2 +- libcxx/include/experimental/list | 2 +- libcxx/include/experimental/map | 4 ++-- libcxx/include/forward_list | 12 ++++++++++-- libcxx/include/list | 12 ++++++++++-- libcxx/include/map | 12 ++++++++++-- libcxx/include/regex | 12 ++++++++++-- libcxx/include/set | 12 ++++++++++-- libcxx/include/unordered_map | 12 ++++++++++-- libcxx/include/unordered_set | 12 ++++++++++-- libcxx/include/vector | 10 ++++++++-- libcxx/src/support/runtime/memory_resource_msvc.ipp | 2 -- 22 files changed, 107 insertions(+), 40 deletions(-) diff --git a/libcxx/include/__fwd/memory_resource.h b/libcxx/include/__fwd/memory_resource.h index b6c85d8d69d30..b280858befce2 100644 --- a/libcxx/include/__fwd/memory_resource.h +++ b/libcxx/include/__fwd/memory_resource.h @@ -15,7 +15,7 @@ # pragma GCC system_header #endif -namespace std { // purposefully not using versioning namespace +namespace std { // purposefully not using versioning namespace namespace pmr { template diff --git a/libcxx/include/__fwd/string.h b/libcxx/include/__fwd/string.h index 234b7767e0497..ea7cb25c56a9d 100644 --- a/libcxx/include/__fwd/string.h +++ b/libcxx/include/__fwd/string.h @@ -90,7 +90,7 @@ namespace std { namespace pmr { template > -using basic_string = std::basic_string<_CharT, _Traits, std::pmr::polymorphic_allocator<_CharT>>; +using basic_string = std::basic_string<_CharT, _Traits, polymorphic_allocator<_CharT>>; using string = basic_string; diff --git a/libcxx/include/__memory_resource/memory_resource.h b/libcxx/include/__memory_resource/memory_resource.h index cedf53d15f13e..1dfe4c45b3e05 100644 --- a/libcxx/include/__memory_resource/memory_resource.h +++ b/libcxx/include/__memory_resource/memory_resource.h @@ -18,8 +18,7 @@ #if _LIBCPP_STD_VER > 14 -namespace std // purposefully not using versioning namespace -{ +namespace std { // purposefully not using versioning namespace namespace pmr { diff --git a/libcxx/include/__memory_resource/monotonic_buffer_resource.h b/libcxx/include/__memory_resource/monotonic_buffer_resource.h index 3fa7473bfc5cd..a663a777a6de2 100644 --- a/libcxx/include/__memory_resource/monotonic_buffer_resource.h +++ b/libcxx/include/__memory_resource/monotonic_buffer_resource.h @@ -20,7 +20,7 @@ #if _LIBCPP_STD_VER > 14 -namespace std { // purposefully not using versioning namespace +namespace std { // purposefully not using versioning namespace namespace pmr { @@ -112,7 +112,7 @@ class _LIBCPP_TYPE_VIS monotonic_buffer_resource : public memory_resource { } // namespace pmr -} +} // namespace std #endif // _LIBCPP_STD_VER > 14 diff --git a/libcxx/include/__memory_resource/polymorphic_allocator.h b/libcxx/include/__memory_resource/polymorphic_allocator.h index c22b3b053192d..b5b067d255fe1 100644 --- a/libcxx/include/__memory_resource/polymorphic_allocator.h +++ b/libcxx/include/__memory_resource/polymorphic_allocator.h @@ -12,6 +12,7 @@ #include <__assert> #include <__config> #include <__memory_resource/memory_resource.h> +#include <__utility/transaction.h> #include #include #include @@ -27,7 +28,7 @@ _LIBCPP_PUSH_MACROS #if _LIBCPP_STD_VER > 14 -namespace std { // purposefully not using versioning namespace +namespace std { // purposefully not using versioning namespace namespace pmr { @@ -214,7 +215,7 @@ operator!=(const polymorphic_allocator<_Tp>& __lhs, const polymorphic_allocator< } // namespace pmr -} +} // namespace std #endif // _LIBCPP_STD_VER > 14 diff --git a/libcxx/include/__memory_resource/pool_options.h b/libcxx/include/__memory_resource/pool_options.h index 60cebc4c0d844..ac9600ed8e564 100644 --- a/libcxx/include/__memory_resource/pool_options.h +++ b/libcxx/include/__memory_resource/pool_options.h @@ -18,7 +18,7 @@ #if _LIBCPP_STD_VER > 14 -namespace std { // purposefully not using versioning namespace +namespace std { // purposefully not using versioning namespace namespace pmr { @@ -31,7 +31,7 @@ struct _LIBCPP_TYPE_VIS pool_options { } // namespace pmr -} +} // namespace std #endif // _LIBCPP_STD_VER > 14 diff --git a/libcxx/include/__memory_resource/synchronized_pool_resource.h b/libcxx/include/__memory_resource/synchronized_pool_resource.h index 18b53f79f713e..218ae3342123a 100644 --- a/libcxx/include/__memory_resource/synchronized_pool_resource.h +++ b/libcxx/include/__memory_resource/synchronized_pool_resource.h @@ -24,7 +24,7 @@ #if _LIBCPP_STD_VER > 14 -namespace std { // purposefully not using versioning namespace +namespace std { // purposefully not using versioning namespace namespace pmr { @@ -87,7 +87,7 @@ class _LIBCPP_TYPE_VIS synchronized_pool_resource : public memory_resource { } // namespace pmr -} +} // namespace std #endif // _LIBCPP_STD_VER > 14 diff --git a/libcxx/include/__memory_resource/unsynchronized_pool_resource.h b/libcxx/include/__memory_resource/unsynchronized_pool_resource.h index 281f053d076ef..cd354dcc73e08 100644 --- a/libcxx/include/__memory_resource/unsynchronized_pool_resource.h +++ b/libcxx/include/__memory_resource/unsynchronized_pool_resource.h @@ -21,7 +21,7 @@ #if _LIBCPP_STD_VER > 14 -namespace std { // purposefully not using versioning namespace +namespace std { // purposefully not using versioning namespace namespace pmr { @@ -99,7 +99,7 @@ class _LIBCPP_TYPE_VIS unsynchronized_pool_resource : public memory_resource { } // namespace pmr -} +} // namespace std #endif // _LIBCPP_STD_VER > 14 diff --git a/libcxx/include/deque b/libcxx/include/deque index ae6d6f4c15c83..2d91048e7420d 100644 --- a/libcxx/include/deque +++ b/libcxx/include/deque @@ -2932,10 +2932,17 @@ inline constexpr bool __format::__enable_insertable> = true; _LIBCPP_END_NAMESPACE_STD #if _LIBCPP_STD_VER > 14 -_LIBCPP_BEGIN_NAMESPACE_STD_PMR +namespace std { + +namespace pmr { + template -using deque = std::deque<_ValueT, std::pmr::polymorphic_allocator<_ValueT>>; -_LIBCPP_END_NAMESPACE_STD_PMR +using deque = std::deque<_ValueT, polymorphic_allocator<_ValueT>>; + +} // namespace pmr + +} // namespace std + #endif _LIBCPP_POP_MACROS diff --git a/libcxx/include/experimental/deque b/libcxx/include/experimental/deque index 430b31d7447dd..46962afbb795e 100644 --- a/libcxx/include/experimental/deque +++ b/libcxx/include/experimental/deque @@ -43,7 +43,7 @@ _LIBCPP_BEGIN_NAMESPACE_LFTS_PMR #ifndef _LIBCPP_CXX03_LANG template -using deque = _VSTD::deque<_ValueT, std::pmr::polymorphic_allocator<_ValueT>>; +using deque = _VSTD::deque<_ValueT, polymorphic_allocator<_ValueT>>; #endif // _LIBCPP_CXX03_LANG diff --git a/libcxx/include/experimental/forward_list b/libcxx/include/experimental/forward_list index 59886d7eb458e..5d2686deb2768 100644 --- a/libcxx/include/experimental/forward_list +++ b/libcxx/include/experimental/forward_list @@ -43,7 +43,7 @@ _LIBCPP_BEGIN_NAMESPACE_LFTS_PMR #ifndef _LIBCPP_CXX03_LANG template -using forward_list = _VSTD::forward_list<_ValueT, std::pmr::polymorphic_allocator<_ValueT>>; +using forward_list = _VSTD::forward_list<_ValueT, polymorphic_allocator<_ValueT>>; #endif // _LIBCPP_CXX03_LANG diff --git a/libcxx/include/experimental/list b/libcxx/include/experimental/list index 62d7f59e95a67..06abe8702241e 100644 --- a/libcxx/include/experimental/list +++ b/libcxx/include/experimental/list @@ -43,7 +43,7 @@ _LIBCPP_BEGIN_NAMESPACE_LFTS_PMR #ifndef _LIBCPP_CXX03_LANG template -using list = _VSTD::list<_ValueT, std::pmr::polymorphic_allocator<_ValueT>>; +using list = _VSTD::list<_ValueT, polymorphic_allocator<_ValueT>>; #endif // _LIBCPP_CXX03_LANG diff --git a/libcxx/include/experimental/map b/libcxx/include/experimental/map index 5730562801519..8ec94e4a5bc86 100644 --- a/libcxx/include/experimental/map +++ b/libcxx/include/experimental/map @@ -49,11 +49,11 @@ _LIBCPP_BEGIN_NAMESPACE_LFTS_PMR template > using map = _VSTD::map<_Key, _Value, _Compare, - std::pmr::polymorphic_allocator>>; + polymorphic_allocator>>; template > using multimap = _VSTD::multimap<_Key, _Value, _Compare, - std::pmr::polymorphic_allocator>>; + polymorphic_allocator>>; #endif // _LIBCPP_CXX03_LANG diff --git a/libcxx/include/forward_list b/libcxx/include/forward_list index d3ae6073d44b8..ac441b422df1a 100644 --- a/libcxx/include/forward_list +++ b/libcxx/include/forward_list @@ -1780,10 +1780,18 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_END_NAMESPACE_STD #if _LIBCPP_STD_VER > 14 -_LIBCPP_BEGIN_NAMESPACE_STD_PMR + +namespace std { + +namespace pmr { + template using forward_list = std::forward_list<_ValueT, std::pmr::polymorphic_allocator<_ValueT>>; -_LIBCPP_END_NAMESPACE_STD_PMR + +} // namespace pmr + +} // namespace std + #endif _LIBCPP_POP_MACROS diff --git a/libcxx/include/list b/libcxx/include/list index c25c24aa551b5..027b1cbb1c0dc 100644 --- a/libcxx/include/list +++ b/libcxx/include/list @@ -2363,10 +2363,18 @@ inline constexpr bool __format::__enable_insertable> = true; _LIBCPP_END_NAMESPACE_STD #if _LIBCPP_STD_VER > 14 -_LIBCPP_BEGIN_NAMESPACE_STD_PMR + +namespace std { + +namespace pmr { + template using list = std::list<_ValueT, std::pmr::polymorphic_allocator<_ValueT>>; -_LIBCPP_END_NAMESPACE_STD_PMR + +} // namespace pmr + +} // namespace std + #endif _LIBCPP_POP_MACROS diff --git a/libcxx/include/map b/libcxx/include/map index 580693e58c68d..df3da627680ef 100644 --- a/libcxx/include/map +++ b/libcxx/include/map @@ -2340,13 +2340,21 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_END_NAMESPACE_STD #if _LIBCPP_STD_VER > 14 -_LIBCPP_BEGIN_NAMESPACE_STD_PMR + +namespace std { + +namespace pmr { + template > using map = std::map<_KeyT, _ValueT, _CompareT, std::pmr::polymorphic_allocator>>; template > using multimap = std::multimap<_KeyT, _ValueT, _CompareT, std::pmr::polymorphic_allocator>>; -_LIBCPP_END_NAMESPACE_STD_PMR + +} // namespace pmr + +} // namespace std + #endif #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 diff --git a/libcxx/include/regex b/libcxx/include/regex index e728edefdb744..06f2201c60455 100644 --- a/libcxx/include/regex +++ b/libcxx/include/regex @@ -6845,7 +6845,11 @@ regex_replace(const _CharT* __s, _LIBCPP_END_NAMESPACE_STD #if _LIBCPP_STD_VER > 14 -_LIBCPP_BEGIN_NAMESPACE_STD_PMR + +namespace std { + +namespace pmr { + template using match_results = std::match_results<_BidirT, std::pmr::polymorphic_allocator>>; @@ -6856,7 +6860,11 @@ using smatch = match_results; using wcmatch = match_results; using wsmatch = match_results; #endif -_LIBCPP_END_NAMESPACE_STD_PMR + +} // namespace pmr + +} // namespace std + #endif _LIBCPP_POP_MACROS diff --git a/libcxx/include/set b/libcxx/include/set index fa95560a3d4ed..da8c8d1ce3d99 100644 --- a/libcxx/include/set +++ b/libcxx/include/set @@ -1585,13 +1585,21 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_END_NAMESPACE_STD #if _LIBCPP_STD_VER > 14 -_LIBCPP_BEGIN_NAMESPACE_STD_PMR + +namespace std { + +namespace pmr { + template > using set = std::set<_KeyT, _CompareT, std::pmr::polymorphic_allocator<_KeyT>>; template > using multiset = std::multiset<_KeyT, _CompareT, std::pmr::polymorphic_allocator<_KeyT>>; -_LIBCPP_END_NAMESPACE_STD_PMR + +} // namespace pmr + +} // namespace std + #endif #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 diff --git a/libcxx/include/unordered_map b/libcxx/include/unordered_map index a7f9a1a6b9e89..2358062f72c08 100644 --- a/libcxx/include/unordered_map +++ b/libcxx/include/unordered_map @@ -2630,7 +2630,11 @@ operator!=(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, _LIBCPP_END_NAMESPACE_STD #if _LIBCPP_STD_VER > 14 -_LIBCPP_BEGIN_NAMESPACE_STD_PMR + +namespace std { + +namespace pmr { + template , class _PredT = std::equal_to<_KeyT>> using unordered_map = std::unordered_map<_KeyT, _ValueT, _HashT, _PredT, std::pmr::polymorphic_allocator>>; @@ -2638,7 +2642,11 @@ using unordered_map = template , class _PredT = std::equal_to<_KeyT>> using unordered_multimap = std::unordered_multimap<_KeyT, _ValueT, _HashT, _PredT, std::pmr::polymorphic_allocator>>; -_LIBCPP_END_NAMESPACE_STD_PMR + +} // namespace pmr + +} // namespace std + #endif #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 diff --git a/libcxx/include/unordered_set b/libcxx/include/unordered_set index 4bf600d292a11..47708eeaa165f 100644 --- a/libcxx/include/unordered_set +++ b/libcxx/include/unordered_set @@ -1804,13 +1804,21 @@ operator!=(const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x, _LIBCPP_END_NAMESPACE_STD #if _LIBCPP_STD_VER > 14 -_LIBCPP_BEGIN_NAMESPACE_STD_PMR + +namespace std { + +namespace pmr { + template , class _PredT = std::equal_to<_KeyT>> using unordered_set = std::unordered_set<_KeyT, _HashT, _PredT, std::pmr::polymorphic_allocator<_KeyT>>; template , class _PredT = std::equal_to<_KeyT>> using unordered_multiset = std::unordered_multiset<_KeyT, _HashT, _PredT, std::pmr::polymorphic_allocator<_KeyT>>; -_LIBCPP_END_NAMESPACE_STD_PMR + +} // namespace pmr + +} // namespace std + #endif #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 diff --git a/libcxx/include/vector b/libcxx/include/vector index d1277b94e0f64..89d5ae8109cf1 100644 --- a/libcxx/include/vector +++ b/libcxx/include/vector @@ -3272,12 +3272,18 @@ inline constexpr bool __format::__enable_insertable> = true _LIBCPP_END_NAMESPACE_STD #if _LIBCPP_STD_VER > 14 -_LIBCPP_BEGIN_NAMESPACE_STD_PMR + +namespace std { + namespace pmr { + template using vector = std::vector<_ValueT, std::pmr::polymorphic_allocator<_ValueT>>; + } // namespace pmr -_LIBCPP_END_NAMESPACE_STD_PMR + +} // namespace std + #endif _LIBCPP_POP_MACROS diff --git a/libcxx/src/support/runtime/memory_resource_msvc.ipp b/libcxx/src/support/runtime/memory_resource_msvc.ipp index 96b25434deef4..9f28f58a4e7b7 100644 --- a/libcxx/src/support/runtime/memory_resource_msvc.ipp +++ b/libcxx/src/support/runtime/memory_resource_msvc.ipp @@ -30,7 +30,6 @@ namespace std { namespace pmr { memory_resource* get_default_resource() noexcept { - printf("Debug: compat get_default_resouce\n"); #ifdef __cpp_aligned_new return ::_Aligned_get_default_resource(); #else @@ -39,7 +38,6 @@ memory_resource* get_default_resource() noexcept { } memory_resource* set_default_resource(memory_resource* __new_res) noexcept { - printf("Debug: compat set_default_resouce\n"); #ifdef __cpp_aligned_new return ::_Aligned_set_default_resource(__new_res); #else From 031c39ddeab7161d7cae4a1098336638712c2a01 Mon Sep 17 00:00:00 2001 From: kboyarinov Date: Thu, 22 Dec 2022 10:54:29 -0600 Subject: [PATCH 10/26] More cosmetic changes --- libcxx/include/__fwd/string.h | 1 - libcxx/include/deque | 2 -- libcxx/include/forward_list | 4 +--- libcxx/include/list | 4 +--- libcxx/include/map | 6 ++---- libcxx/include/regex | 4 +--- libcxx/include/set | 6 ++---- libcxx/include/unordered_map | 6 ++---- libcxx/include/unordered_set | 6 ++---- libcxx/include/vector | 4 +--- 10 files changed, 12 insertions(+), 31 deletions(-) diff --git a/libcxx/include/__fwd/string.h b/libcxx/include/__fwd/string.h index ea7cb25c56a9d..0e4be581d5de3 100644 --- a/libcxx/include/__fwd/string.h +++ b/libcxx/include/__fwd/string.h @@ -106,7 +106,6 @@ using u16string = basic_string; using u32string = basic_string; } // namespace pmr - } // namespace std #endif // _LIBCPP_STD_VER >= 17 diff --git a/libcxx/include/deque b/libcxx/include/deque index 2d91048e7420d..5b31b6da97b10 100644 --- a/libcxx/include/deque +++ b/libcxx/include/deque @@ -2935,10 +2935,8 @@ _LIBCPP_END_NAMESPACE_STD namespace std { namespace pmr { - template using deque = std::deque<_ValueT, polymorphic_allocator<_ValueT>>; - } // namespace pmr } // namespace std diff --git a/libcxx/include/forward_list b/libcxx/include/forward_list index ac441b422df1a..4873ad5e004d9 100644 --- a/libcxx/include/forward_list +++ b/libcxx/include/forward_list @@ -1784,10 +1784,8 @@ _LIBCPP_END_NAMESPACE_STD namespace std { namespace pmr { - template -using forward_list = std::forward_list<_ValueT, std::pmr::polymorphic_allocator<_ValueT>>; - +using forward_list = std::forward_list<_ValueT, polymorphic_allocator<_ValueT>>; } // namespace pmr } // namespace std diff --git a/libcxx/include/list b/libcxx/include/list index 027b1cbb1c0dc..c79a617595913 100644 --- a/libcxx/include/list +++ b/libcxx/include/list @@ -2367,10 +2367,8 @@ _LIBCPP_END_NAMESPACE_STD namespace std { namespace pmr { - template -using list = std::list<_ValueT, std::pmr::polymorphic_allocator<_ValueT>>; - +using list = std::list<_ValueT, polymorphic_allocator<_ValueT>>; } // namespace pmr } // namespace std diff --git a/libcxx/include/map b/libcxx/include/map index df3da627680ef..34956149c60c1 100644 --- a/libcxx/include/map +++ b/libcxx/include/map @@ -2344,13 +2344,11 @@ _LIBCPP_END_NAMESPACE_STD namespace std { namespace pmr { - template > -using map = std::map<_KeyT, _ValueT, _CompareT, std::pmr::polymorphic_allocator>>; +using map = std::map<_KeyT, _ValueT, _CompareT, polymorphic_allocator>>; template > -using multimap = std::multimap<_KeyT, _ValueT, _CompareT, std::pmr::polymorphic_allocator>>; - +using multimap = std::multimap<_KeyT, _ValueT, _CompareT, polymorphic_allocator>>; } // namespace pmr } // namespace std diff --git a/libcxx/include/regex b/libcxx/include/regex index 06f2201c60455..69dc9f567a5e9 100644 --- a/libcxx/include/regex +++ b/libcxx/include/regex @@ -6849,9 +6849,8 @@ _LIBCPP_END_NAMESPACE_STD namespace std { namespace pmr { - template -using match_results = std::match_results<_BidirT, std::pmr::polymorphic_allocator>>; +using match_results = std::match_results<_BidirT, polymorphic_allocator>>; using cmatch = match_results; using smatch = match_results; @@ -6860,7 +6859,6 @@ using smatch = match_results; using wcmatch = match_results; using wsmatch = match_results; #endif - } // namespace pmr } // namespace std diff --git a/libcxx/include/set b/libcxx/include/set index da8c8d1ce3d99..24ede7521725e 100644 --- a/libcxx/include/set +++ b/libcxx/include/set @@ -1589,13 +1589,11 @@ _LIBCPP_END_NAMESPACE_STD namespace std { namespace pmr { - template > -using set = std::set<_KeyT, _CompareT, std::pmr::polymorphic_allocator<_KeyT>>; +using set = std::set<_KeyT, _CompareT, polymorphic_allocator<_KeyT>>; template > -using multiset = std::multiset<_KeyT, _CompareT, std::pmr::polymorphic_allocator<_KeyT>>; - +using multiset = std::multiset<_KeyT, _CompareT, polymorphic_allocator<_KeyT>>; } // namespace pmr } // namespace std diff --git a/libcxx/include/unordered_map b/libcxx/include/unordered_map index 2358062f72c08..7c7707d1c14cb 100644 --- a/libcxx/include/unordered_map +++ b/libcxx/include/unordered_map @@ -2634,15 +2634,13 @@ _LIBCPP_END_NAMESPACE_STD namespace std { namespace pmr { - template , class _PredT = std::equal_to<_KeyT>> using unordered_map = - std::unordered_map<_KeyT, _ValueT, _HashT, _PredT, std::pmr::polymorphic_allocator>>; + std::unordered_map<_KeyT, _ValueT, _HashT, _PredT, polymorphic_allocator>>; template , class _PredT = std::equal_to<_KeyT>> using unordered_multimap = - std::unordered_multimap<_KeyT, _ValueT, _HashT, _PredT, std::pmr::polymorphic_allocator>>; - + std::unordered_multimap<_KeyT, _ValueT, _HashT, _PredT, polymorphic_allocator>>; } // namespace pmr } // namespace std diff --git a/libcxx/include/unordered_set b/libcxx/include/unordered_set index 47708eeaa165f..a346d38c2ce69 100644 --- a/libcxx/include/unordered_set +++ b/libcxx/include/unordered_set @@ -1808,13 +1808,11 @@ _LIBCPP_END_NAMESPACE_STD namespace std { namespace pmr { - template , class _PredT = std::equal_to<_KeyT>> -using unordered_set = std::unordered_set<_KeyT, _HashT, _PredT, std::pmr::polymorphic_allocator<_KeyT>>; +using unordered_set = std::unordered_set<_KeyT, _HashT, _PredT, polymorphic_allocator<_KeyT>>; template , class _PredT = std::equal_to<_KeyT>> -using unordered_multiset = std::unordered_multiset<_KeyT, _HashT, _PredT, std::pmr::polymorphic_allocator<_KeyT>>; - +using unordered_multiset = std::unordered_multiset<_KeyT, _HashT, _PredT, polymorphic_allocator<_KeyT>>; } // namespace pmr } // namespace std diff --git a/libcxx/include/vector b/libcxx/include/vector index 89d5ae8109cf1..468f37ec4c2e9 100644 --- a/libcxx/include/vector +++ b/libcxx/include/vector @@ -3276,10 +3276,8 @@ _LIBCPP_END_NAMESPACE_STD namespace std { namespace pmr { - template -using vector = std::vector<_ValueT, std::pmr::polymorphic_allocator<_ValueT>>; - +using vector = std::vector<_ValueT, polymorphic_allocator<_ValueT>>; } // namespace pmr } // namespace std From fe69e9630dcbd544838f1777501d59a72d4264af Mon Sep 17 00:00:00 2001 From: kboyarinov Date: Mon, 26 Dec 2022 14:06:44 +0200 Subject: [PATCH 11/26] Fix string and fallback compilation --- libcxx/include/__fwd/string.h | 54 ++++++------ .../runtime/memory_resource_fallback.ipp | 88 +++++++++---------- 2 files changed, 73 insertions(+), 69 deletions(-) diff --git a/libcxx/include/__fwd/string.h b/libcxx/include/__fwd/string.h index 0e4be581d5de3..24e3bf3e524de 100644 --- a/libcxx/include/__fwd/string.h +++ b/libcxx/include/__fwd/string.h @@ -57,35 +57,10 @@ using u8string = basic_string; using u16string = basic_string; using u32string = basic_string; -// clang-format off -template -class _LIBCPP_PREFERRED_NAME(string) -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS - _LIBCPP_PREFERRED_NAME(wstring) -#endif -#ifndef _LIBCPP_HAS_NO_CHAR8_T - _LIBCPP_PREFERRED_NAME(u8string) -#endif - _LIBCPP_PREFERRED_NAME(u16string) - _LIBCPP_PREFERRED_NAME(u32string) #if _LIBCPP_STD_VER >= 17 - _LIBCPP_PREFERRED_NAME(pmr::string) -# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS - _LIBCPP_PREFERRED_NAME(pmr::wstring) -# endif -# ifndef _LIBCPP_HAS_NO_CHAR8_T - _LIBCPP_PREFERRED_NAME(pmr::u8string) -# endif - _LIBCPP_PREFERRED_NAME(pmr::u16string) - _LIBCPP_PREFERRED_NAME(pmr::u32string) -#endif - basic_string; -// clang-format on _LIBCPP_END_NAMESPACE_STD -#if _LIBCPP_STD_VER >= 17 - namespace std { namespace pmr { @@ -108,6 +83,35 @@ using u32string = basic_string; } // namespace pmr } // namespace std +_LIBCPP_BEGIN_NAMESPACE_STD + #endif // _LIBCPP_STD_VER >= 17 +// clang-format off +template +class _LIBCPP_PREFERRED_NAME(string) +#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS + _LIBCPP_PREFERRED_NAME(wstring) +#endif +#ifndef _LIBCPP_HAS_NO_CHAR8_T + _LIBCPP_PREFERRED_NAME(u8string) +#endif + _LIBCPP_PREFERRED_NAME(u16string) + _LIBCPP_PREFERRED_NAME(u32string) +#if _LIBCPP_STD_VER >= 17 + _LIBCPP_PREFERRED_NAME(pmr::string) +# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS + _LIBCPP_PREFERRED_NAME(pmr::wstring) +# endif +# ifndef _LIBCPP_HAS_NO_CHAR8_T + _LIBCPP_PREFERRED_NAME(pmr::u8string) +# endif + _LIBCPP_PREFERRED_NAME(pmr::u16string) + _LIBCPP_PREFERRED_NAME(pmr::u32string) +#endif + basic_string; +// clang-format on + +_LIBCPP_END_NAMESPACE_STD + #endif // _LIBCPP___FWD_STRING_H diff --git a/libcxx/src/support/runtime/memory_resource_fallback.ipp b/libcxx/src/support/runtime/memory_resource_fallback.ipp index 9685c498b20c7..b31cb886ebc2c 100644 --- a/libcxx/src/support/runtime/memory_resource_fallback.ipp +++ b/libcxx/src/support/runtime/memory_resource_fallback.ipp @@ -11,50 +11,6 @@ namespace std { namespace pmr { -// default_memory_resource() - -static memory_resource* __default_memory_resource(bool set = false, memory_resource* new_res = nullptr) noexcept { -#ifndef _LIBCPP_HAS_NO_ATOMIC_HEADER - static constinit atomic __res{&res_init.resources.new_delete_res}; - if (set) { - new_res = new_res ? new_res : new_delete_resource(); - // TODO: Can a weaker ordering be used? - return std::atomic_exchange_explicit(&__res, new_res, memory_order_acq_rel); - } else { - return std::atomic_load_explicit(&__res, memory_order_acquire); - } -#elif !defined(_LIBCPP_HAS_NO_THREADS) - static constinit memory_resource* res = &res_init.resources.new_delete_res; - static mutex res_lock; - if (set) { - new_res = new_res ? new_res : new_delete_resource(); - lock_guard guard(res_lock); - memory_resource* old_res = res; - res = new_res; - return old_res; - } else { - lock_guard guard(res_lock); - return res; - } -#else - static constinit memory_resource* res = &res_init.resources.new_delete_res; - if (set) { - new_res = new_res ? new_res : new_delete_resource(); - memory_resource* old_res = res; - res = new_res; - return old_res; - } else { - return res; - } -#endif -} - -memory_resource* get_default_resource() noexcept { return __default_memory_resource(); } - -memory_resource* set_default_resource(memory_resource* __new_res) noexcept { - return __default_memory_resource(true, __new_res); -} - // new_delete_resource() #ifdef _LIBCPP_HAS_NO_ALIGNED_ALLOCATION @@ -117,5 +73,49 @@ memory_resource* new_delete_resource() noexcept { return &res_init.resources.new memory_resource* null_memory_resource() noexcept { return &res_init.resources.null_res; } +// default_memory_resource() + +static memory_resource* __default_memory_resource(bool set = false, memory_resource* new_res = nullptr) noexcept { +#ifndef _LIBCPP_HAS_NO_ATOMIC_HEADER + static constinit atomic __res{&res_init.resources.new_delete_res}; + if (set) { + new_res = new_res ? new_res : new_delete_resource(); + // TODO: Can a weaker ordering be used? + return std::atomic_exchange_explicit(&__res, new_res, memory_order_acq_rel); + } else { + return std::atomic_load_explicit(&__res, memory_order_acquire); + } +#elif !defined(_LIBCPP_HAS_NO_THREADS) + static constinit memory_resource* res = &res_init.resources.new_delete_res; + static mutex res_lock; + if (set) { + new_res = new_res ? new_res : new_delete_resource(); + lock_guard guard(res_lock); + memory_resource* old_res = res; + res = new_res; + return old_res; + } else { + lock_guard guard(res_lock); + return res; + } +#else + static constinit memory_resource* res = &res_init.resources.new_delete_res; + if (set) { + new_res = new_res ? new_res : new_delete_resource(); + memory_resource* old_res = res; + res = new_res; + return old_res; + } else { + return res; + } +#endif +} + +memory_resource* get_default_resource() noexcept { return __default_memory_resource(); } + +memory_resource* set_default_resource(memory_resource* __new_res) noexcept { + return __default_memory_resource(true, __new_res); +} + } // namespace pmr } // namespace std From 5a4b192df5c1da9d7e312e4186ff037c58596243 Mon Sep 17 00:00:00 2001 From: kboyarinov Date: Mon, 9 Jan 2023 13:22:17 +0200 Subject: [PATCH 12/26] Remove unnecessary whitespace changes in vector --- libcxx/include/vector | 46 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/libcxx/include/vector b/libcxx/include/vector index 468f37ec4c2e9..092a8969a3c7d 100644 --- a/libcxx/include/vector +++ b/libcxx/include/vector @@ -12,8 +12,10 @@ /* vector synopsis + namespace std { + template > class vector { @@ -30,6 +32,7 @@ public: typedef typename allocator_type::const_pointer const_pointer; typedef std::reverse_iterator reverse_iterator; typedef std::reverse_iterator const_reverse_iterator; + vector() noexcept(is_nothrow_default_constructible::value); explicit vector(const allocator_type&); @@ -54,40 +57,50 @@ public: void assign(InputIterator first, InputIterator last); void assign(size_type n, const value_type& u); void assign(initializer_list il); + allocator_type get_allocator() const noexcept; + iterator begin() noexcept; const_iterator begin() const noexcept; iterator end() noexcept; const_iterator end() const noexcept; + reverse_iterator rbegin() noexcept; const_reverse_iterator rbegin() const noexcept; reverse_iterator rend() noexcept; const_reverse_iterator rend() const noexcept; + const_iterator cbegin() const noexcept; const_iterator cend() const noexcept; const_reverse_iterator crbegin() const noexcept; const_reverse_iterator crend() const noexcept; + size_type size() const noexcept; size_type max_size() const noexcept; size_type capacity() const noexcept; bool empty() const noexcept; void reserve(size_type n); void shrink_to_fit() noexcept; + reference operator[](size_type n); const_reference operator[](size_type n) const; reference at(size_type n); const_reference at(size_type n) const; + reference front(); const_reference front() const; reference back(); const_reference back() const; + value_type* data() noexcept; const value_type* data() const noexcept; + void push_back(const value_type& x); void push_back(value_type&& x); template reference emplace_back(Args&&... args); // reference in C++17 void pop_back(); + template iterator emplace(const_iterator position, Args&&... args); iterator insert(const_iterator position, const value_type& x); iterator insert(const_iterator position, value_type&& x); @@ -95,16 +108,22 @@ public: template iterator insert(const_iterator position, InputIterator first, InputIterator last); iterator insert(const_iterator position, initializer_list il); + iterator erase(const_iterator position); iterator erase(const_iterator first, const_iterator last); + void clear() noexcept; + void resize(size_type sz); void resize(size_type sz, const value_type& c); + void swap(vector&) noexcept(allocator_traits::propagate_on_container_swap::value || allocator_traits::is_always_equal::value); // C++17 + bool __invariants() const; }; + template > class vector { @@ -119,6 +138,7 @@ public: typedef const_iterator const_pointer; typedef std::reverse_iterator reverse_iterator; typedef std::reverse_iterator const_reverse_iterator; + class reference { public: @@ -129,6 +149,7 @@ public: iterator operator&() const noexcept; void flip() noexcept; }; + class const_reference { public: @@ -136,6 +157,7 @@ public: operator bool() const noexcept; const_iterator operator&() const noexcept; }; + vector() noexcept(is_nothrow_default_constructible::value); explicit vector(const allocator_type&); @@ -159,73 +181,94 @@ public: void assign(InputIterator first, InputIterator last); void assign(size_type n, const value_type& u); void assign(initializer_list il); + allocator_type get_allocator() const noexcept; + iterator begin() noexcept; const_iterator begin() const noexcept; iterator end() noexcept; const_iterator end() const noexcept; + reverse_iterator rbegin() noexcept; const_reverse_iterator rbegin() const noexcept; reverse_iterator rend() noexcept; const_reverse_iterator rend() const noexcept; + const_iterator cbegin() const noexcept; const_iterator cend() const noexcept; const_reverse_iterator crbegin() const noexcept; const_reverse_iterator crend() const noexcept; + size_type size() const noexcept; size_type max_size() const noexcept; size_type capacity() const noexcept; bool empty() const noexcept; void reserve(size_type n); void shrink_to_fit() noexcept; + reference operator[](size_type n); const_reference operator[](size_type n) const; reference at(size_type n); const_reference at(size_type n) const; + reference front(); const_reference front() const; reference back(); const_reference back() const; + void push_back(const value_type& x); template reference emplace_back(Args&&... args); // C++14; reference in C++17 void pop_back(); + template iterator emplace(const_iterator position, Args&&... args); // C++14 iterator insert(const_iterator position, const value_type& x); iterator insert(const_iterator position, size_type n, const value_type& x); template iterator insert(const_iterator position, InputIterator first, InputIterator last); iterator insert(const_iterator position, initializer_list il); + iterator erase(const_iterator position); iterator erase(const_iterator first, const_iterator last); + void clear() noexcept; + void resize(size_type sz); void resize(size_type sz, value_type x); + void swap(vector&) noexcept(allocator_traits::propagate_on_container_swap::value || allocator_traits::is_always_equal::value); // C++17 void flip() noexcept; + bool __invariants() const; }; + template ::value_type>> vector(InputIterator, InputIterator, Allocator = Allocator()) -> vector::value_type, Allocator>; // C++17 + template struct hash>; + template bool operator==(const vector& x, const vector& y); template bool operator< (const vector& x, const vector& y); template bool operator!=(const vector& x, const vector& y); template bool operator> (const vector& x, const vector& y); template bool operator>=(const vector& x, const vector& y); template bool operator<=(const vector& x, const vector& y); + template void swap(vector& x, vector& y) noexcept(noexcept(x.swap(y))); + template typename vector::size_type erase(vector& c, const U& value); // C++20 template typename vector::size_type erase_if(vector& c, Predicate pred); // C++20 + } // std + */ #include <__algorithm/copy.h> @@ -3272,7 +3315,6 @@ inline constexpr bool __format::__enable_insertable> = true _LIBCPP_END_NAMESPACE_STD #if _LIBCPP_STD_VER > 14 - namespace std { namespace pmr { @@ -3281,7 +3323,7 @@ using vector = std::vector<_ValueT, polymorphic_allocator<_ValueT>>; } // namespace pmr } // namespace std - +_LIBCPP_END_NAMESPACE_STD #endif _LIBCPP_POP_MACROS From 39f5c0543866dc5d7637a89a9f49d9472ef04c73 Mon Sep 17 00:00:00 2001 From: kboyarinov Date: Mon, 9 Jan 2023 13:23:32 +0200 Subject: [PATCH 13/26] Add newline for vector --- libcxx/include/vector | 1 + 1 file changed, 1 insertion(+) diff --git a/libcxx/include/vector b/libcxx/include/vector index 092a8969a3c7d..d67c04c76644c 100644 --- a/libcxx/include/vector +++ b/libcxx/include/vector @@ -3323,6 +3323,7 @@ using vector = std::vector<_ValueT, polymorphic_allocator<_ValueT>>; } // namespace pmr } // namespace std + _LIBCPP_END_NAMESPACE_STD #endif From 02603133adaa2667a2d51019d70ba75028bd7d72 Mon Sep 17 00:00:00 2001 From: kboyarinov Date: Thu, 8 Dec 2022 08:18:51 -0600 Subject: [PATCH 14/26] Remove version namespace for memory_resource --- libcxx/include/__config | 2 + libcxx/include/__fwd/memory_resource.h | 4 +- libcxx/include/__fwd/string.h | 11 ++- .../__memory_resource/memory_resource.h | 5 +- .../monotonic_buffer_resource.h | 4 +- .../__memory_resource/polymorphic_allocator.h | 52 +--------- .../include/__memory_resource/pool_options.h | 4 +- .../synchronized_pool_resource.h | 4 +- .../unsynchronized_pool_resource.h | 4 +- libcxx/include/deque | 8 +- libcxx/include/experimental/deque | 2 +- libcxx/include/experimental/forward_list | 2 +- libcxx/include/experimental/list | 2 +- libcxx/include/experimental/map | 4 +- libcxx/include/forward_list | 8 +- libcxx/include/list | 8 +- libcxx/include/map | 10 +- libcxx/include/regex | 8 +- libcxx/include/set | 10 +- libcxx/include/unordered_map | 10 +- libcxx/include/unordered_set | 10 +- libcxx/include/vector | 95 +++++-------------- libcxx/src/memory_resource.cpp | 4 +- 23 files changed, 84 insertions(+), 187 deletions(-) diff --git a/libcxx/include/__config b/libcxx/include/__config index 505ccf95de724..110036f947e51 100644 --- a/libcxx/include/__config +++ b/libcxx/include/__config @@ -647,7 +647,9 @@ typedef __char32_t char32_t; // Inline namespaces are available in Clang/GCC/MSVC regardless of C++ dialect. // clang-format off # define _LIBCPP_BEGIN_NAMESPACE_STD namespace std { inline namespace _LIBCPP_ABI_NAMESPACE { +# define _LIBCPP_BEGIN_NAMESPACE_STD_PMR namespace std { namespace pmr { inline namespace _LIBCPP_ABI_NAMESPACE { # define _LIBCPP_END_NAMESPACE_STD }} +# define _LIBCPP_END_NAMESPACE_STD_PMR }}} # define _VSTD std _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD diff --git a/libcxx/include/__fwd/memory_resource.h b/libcxx/include/__fwd/memory_resource.h index 718a9078d3cfb..a8f71e5270dbd 100644 --- a/libcxx/include/__fwd/memory_resource.h +++ b/libcxx/include/__fwd/memory_resource.h @@ -15,13 +15,13 @@ # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD +namespace std { // purposefully not using versioning namespace namespace pmr { template class _LIBCPP_TEMPLATE_VIS polymorphic_allocator; } // namespace pmr -_LIBCPP_END_NAMESPACE_STD +} #endif // _LIBCPP___FWD_MEMORY_RESOURCE_H diff --git a/libcxx/include/__fwd/string.h b/libcxx/include/__fwd/string.h index 7ab5561b758f2..a4ad4807ab574 100644 --- a/libcxx/include/__fwd/string.h +++ b/libcxx/include/__fwd/string.h @@ -59,9 +59,13 @@ using u32string = basic_string; #if _LIBCPP_STD_VER >= 17 -namespace pmr { +_LIBCPP_END_NAMESPACE_STD +_LIBCPP_BEGIN_NAMESPACE_STD_PMR + +using ___alloc = std::pmr::polymorphic_allocator; + template > -using basic_string = std::basic_string<_CharT, _Traits, polymorphic_allocator<_CharT>>; +using basic_string = std::basic_string<_CharT, _Traits, std::pmr::polymorphic_allocator<_CharT>>; using string = basic_string; @@ -76,7 +80,8 @@ using u8string = basic_string; using u16string = basic_string; using u32string = basic_string; -} // namespace pmr +_LIBCPP_END_NAMESPACE_STD_PMR +_LIBCPP_BEGIN_NAMESPACE_STD #endif // _LIBCPP_STD_VER >= 17 diff --git a/libcxx/include/__memory_resource/memory_resource.h b/libcxx/include/__memory_resource/memory_resource.h index 02fdd081cce5f..cedf53d15f13e 100644 --- a/libcxx/include/__memory_resource/memory_resource.h +++ b/libcxx/include/__memory_resource/memory_resource.h @@ -18,7 +18,8 @@ #if _LIBCPP_STD_VER > 14 -_LIBCPP_BEGIN_NAMESPACE_STD +namespace std // purposefully not using versioning namespace +{ namespace pmr { @@ -68,7 +69,7 @@ inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const memory_resource& __lhs, const } // namespace pmr -_LIBCPP_END_NAMESPACE_STD +} // namespace std #endif // _LIBCPP_STD_VER > 14 diff --git a/libcxx/include/__memory_resource/monotonic_buffer_resource.h b/libcxx/include/__memory_resource/monotonic_buffer_resource.h index 5c35a62b1663c..3fa7473bfc5cd 100644 --- a/libcxx/include/__memory_resource/monotonic_buffer_resource.h +++ b/libcxx/include/__memory_resource/monotonic_buffer_resource.h @@ -20,7 +20,7 @@ #if _LIBCPP_STD_VER > 14 -_LIBCPP_BEGIN_NAMESPACE_STD +namespace std { // purposefully not using versioning namespace namespace pmr { @@ -112,7 +112,7 @@ class _LIBCPP_TYPE_VIS monotonic_buffer_resource : public memory_resource { } // namespace pmr -_LIBCPP_END_NAMESPACE_STD +} #endif // _LIBCPP_STD_VER > 14 diff --git a/libcxx/include/__memory_resource/polymorphic_allocator.h b/libcxx/include/__memory_resource/polymorphic_allocator.h index 8e59dfc55d78c..2c69b33ed338b 100644 --- a/libcxx/include/__memory_resource/polymorphic_allocator.h +++ b/libcxx/include/__memory_resource/polymorphic_allocator.h @@ -12,7 +12,6 @@ #include <__assert> #include <__config> #include <__memory_resource/memory_resource.h> -#include <__utility/transaction.h> #include #include #include @@ -28,19 +27,14 @@ _LIBCPP_PUSH_MACROS #if _LIBCPP_STD_VER > 14 -_LIBCPP_BEGIN_NAMESPACE_STD +namespace std { // purposefully not using versioning namespace namespace pmr { // [mem.poly.allocator.class] -template = 20 - = byte -# endif - > +template class _LIBCPP_TEMPLATE_VIS polymorphic_allocator { - public: using value_type = _ValueType; @@ -72,46 +66,6 @@ class _LIBCPP_TEMPLATE_VIS polymorphic_allocator { __res_->deallocate(__p, __n * sizeof(_ValueType), alignof(_ValueType)); } -# if _LIBCPP_STD_VER >= 20 - - [[nodiscard]] [[using __gnu__: __alloc_size__(2), __alloc_align__(3)]] void* - allocate_bytes(size_t __nbytes, size_t __alignment = alignof(max_align_t)) { - return __res_->allocate(__nbytes, __alignment); - } - - void deallocate_bytes(void* __ptr, size_t __nbytes, size_t __alignment = alignof(max_align_t)) { - __res_->deallocate(__ptr, __nbytes, __alignment); - } - - template - [[nodiscard]] _Type* allocate_object(size_t __n = 1) { - if (numeric_limits::max() / sizeof(_Type) < __n) - std::__throw_bad_array_new_length(); - return static_cast<_Type*>(allocate_bytes(__n * sizeof(_Type), alignof(_Type))); - } - - template - void deallocate_object(_Type* __ptr, size_t __n = 1) { - deallocate_bytes(__ptr, __n * sizeof(_Type), alignof(_Type)); - } - - template - [[nodiscard]] _Type* new_object(_CtorArgs&&... __ctor_args) { - _Type* __ptr = allocate_object<_Type>(); - __transaction __guard([&] { deallocate_object(__ptr); }); - construct(__ptr, std::forward<_CtorArgs>(__ctor_args)...); - __guard.__complete(); - return __ptr; - } - - template - void delete_object(_Type* __ptr) { - destroy(__ptr); - deallocate_object(__ptr); - } - -# endif // _LIBCPP_STD_VER >= 20 - template _LIBCPP_HIDE_FROM_ABI void construct(_Tp* __p, _Ts&&... __args) { std::__user_alloc_construct_impl( @@ -215,7 +169,7 @@ operator!=(const polymorphic_allocator<_Tp>& __lhs, const polymorphic_allocator< } // namespace pmr -_LIBCPP_END_NAMESPACE_STD +} #endif // _LIBCPP_STD_VER > 14 diff --git a/libcxx/include/__memory_resource/pool_options.h b/libcxx/include/__memory_resource/pool_options.h index 11585a0e3bc87..60cebc4c0d844 100644 --- a/libcxx/include/__memory_resource/pool_options.h +++ b/libcxx/include/__memory_resource/pool_options.h @@ -18,7 +18,7 @@ #if _LIBCPP_STD_VER > 14 -_LIBCPP_BEGIN_NAMESPACE_STD +namespace std { // purposefully not using versioning namespace namespace pmr { @@ -31,7 +31,7 @@ struct _LIBCPP_TYPE_VIS pool_options { } // namespace pmr -_LIBCPP_END_NAMESPACE_STD +} #endif // _LIBCPP_STD_VER > 14 diff --git a/libcxx/include/__memory_resource/synchronized_pool_resource.h b/libcxx/include/__memory_resource/synchronized_pool_resource.h index 550223c7d9689..18b53f79f713e 100644 --- a/libcxx/include/__memory_resource/synchronized_pool_resource.h +++ b/libcxx/include/__memory_resource/synchronized_pool_resource.h @@ -24,7 +24,7 @@ #if _LIBCPP_STD_VER > 14 -_LIBCPP_BEGIN_NAMESPACE_STD +namespace std { // purposefully not using versioning namespace namespace pmr { @@ -87,7 +87,7 @@ class _LIBCPP_TYPE_VIS synchronized_pool_resource : public memory_resource { } // namespace pmr -_LIBCPP_END_NAMESPACE_STD +} #endif // _LIBCPP_STD_VER > 14 diff --git a/libcxx/include/__memory_resource/unsynchronized_pool_resource.h b/libcxx/include/__memory_resource/unsynchronized_pool_resource.h index 7270cf19e214a..281f053d076ef 100644 --- a/libcxx/include/__memory_resource/unsynchronized_pool_resource.h +++ b/libcxx/include/__memory_resource/unsynchronized_pool_resource.h @@ -21,7 +21,7 @@ #if _LIBCPP_STD_VER > 14 -_LIBCPP_BEGIN_NAMESPACE_STD +namespace std { // purposefully not using versioning namespace namespace pmr { @@ -99,7 +99,7 @@ class _LIBCPP_TYPE_VIS unsynchronized_pool_resource : public memory_resource { } // namespace pmr -_LIBCPP_END_NAMESPACE_STD +} #endif // _LIBCPP_STD_VER > 14 diff --git a/libcxx/include/deque b/libcxx/include/deque index 8445883397451..a35fd2d182366 100644 --- a/libcxx/include/deque +++ b/libcxx/include/deque @@ -2932,12 +2932,10 @@ inline constexpr bool __format::__enable_insertable> = true; _LIBCPP_END_NAMESPACE_STD #if _LIBCPP_STD_VER > 14 -_LIBCPP_BEGIN_NAMESPACE_STD -namespace pmr { +_LIBCPP_BEGIN_NAMESPACE_STD_PMR template -using deque = std::deque<_ValueT, polymorphic_allocator<_ValueT>>; -} // namespace pmr -_LIBCPP_END_NAMESPACE_STD +using deque = std::deque<_ValueT, std::pmr::polymorphic_allocator<_ValueT>>; +_LIBCPP_END_NAMESPACE_STD_PMR #endif _LIBCPP_POP_MACROS diff --git a/libcxx/include/experimental/deque b/libcxx/include/experimental/deque index 46962afbb795e..430b31d7447dd 100644 --- a/libcxx/include/experimental/deque +++ b/libcxx/include/experimental/deque @@ -43,7 +43,7 @@ _LIBCPP_BEGIN_NAMESPACE_LFTS_PMR #ifndef _LIBCPP_CXX03_LANG template -using deque = _VSTD::deque<_ValueT, polymorphic_allocator<_ValueT>>; +using deque = _VSTD::deque<_ValueT, std::pmr::polymorphic_allocator<_ValueT>>; #endif // _LIBCPP_CXX03_LANG diff --git a/libcxx/include/experimental/forward_list b/libcxx/include/experimental/forward_list index 5d2686deb2768..59886d7eb458e 100644 --- a/libcxx/include/experimental/forward_list +++ b/libcxx/include/experimental/forward_list @@ -43,7 +43,7 @@ _LIBCPP_BEGIN_NAMESPACE_LFTS_PMR #ifndef _LIBCPP_CXX03_LANG template -using forward_list = _VSTD::forward_list<_ValueT, polymorphic_allocator<_ValueT>>; +using forward_list = _VSTD::forward_list<_ValueT, std::pmr::polymorphic_allocator<_ValueT>>; #endif // _LIBCPP_CXX03_LANG diff --git a/libcxx/include/experimental/list b/libcxx/include/experimental/list index 06abe8702241e..62d7f59e95a67 100644 --- a/libcxx/include/experimental/list +++ b/libcxx/include/experimental/list @@ -43,7 +43,7 @@ _LIBCPP_BEGIN_NAMESPACE_LFTS_PMR #ifndef _LIBCPP_CXX03_LANG template -using list = _VSTD::list<_ValueT, polymorphic_allocator<_ValueT>>; +using list = _VSTD::list<_ValueT, std::pmr::polymorphic_allocator<_ValueT>>; #endif // _LIBCPP_CXX03_LANG diff --git a/libcxx/include/experimental/map b/libcxx/include/experimental/map index 8ec94e4a5bc86..5730562801519 100644 --- a/libcxx/include/experimental/map +++ b/libcxx/include/experimental/map @@ -49,11 +49,11 @@ _LIBCPP_BEGIN_NAMESPACE_LFTS_PMR template > using map = _VSTD::map<_Key, _Value, _Compare, - polymorphic_allocator>>; + std::pmr::polymorphic_allocator>>; template > using multimap = _VSTD::multimap<_Key, _Value, _Compare, - polymorphic_allocator>>; + std::pmr::polymorphic_allocator>>; #endif // _LIBCPP_CXX03_LANG diff --git a/libcxx/include/forward_list b/libcxx/include/forward_list index 61dde8167dfcd..d3ae6073d44b8 100644 --- a/libcxx/include/forward_list +++ b/libcxx/include/forward_list @@ -1780,12 +1780,10 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_END_NAMESPACE_STD #if _LIBCPP_STD_VER > 14 -_LIBCPP_BEGIN_NAMESPACE_STD -namespace pmr { +_LIBCPP_BEGIN_NAMESPACE_STD_PMR template -using forward_list = std::forward_list<_ValueT, polymorphic_allocator<_ValueT>>; -} // namespace pmr -_LIBCPP_END_NAMESPACE_STD +using forward_list = std::forward_list<_ValueT, std::pmr::polymorphic_allocator<_ValueT>>; +_LIBCPP_END_NAMESPACE_STD_PMR #endif _LIBCPP_POP_MACROS diff --git a/libcxx/include/list b/libcxx/include/list index a0c732739ca28..c25c24aa551b5 100644 --- a/libcxx/include/list +++ b/libcxx/include/list @@ -2363,12 +2363,10 @@ inline constexpr bool __format::__enable_insertable> = true; _LIBCPP_END_NAMESPACE_STD #if _LIBCPP_STD_VER > 14 -_LIBCPP_BEGIN_NAMESPACE_STD -namespace pmr { +_LIBCPP_BEGIN_NAMESPACE_STD_PMR template -using list = std::list<_ValueT, polymorphic_allocator<_ValueT>>; -} // namespace pmr -_LIBCPP_END_NAMESPACE_STD +using list = std::list<_ValueT, std::pmr::polymorphic_allocator<_ValueT>>; +_LIBCPP_END_NAMESPACE_STD_PMR #endif _LIBCPP_POP_MACROS diff --git a/libcxx/include/map b/libcxx/include/map index 9cf47b245a02a..580693e58c68d 100644 --- a/libcxx/include/map +++ b/libcxx/include/map @@ -2340,15 +2340,13 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_END_NAMESPACE_STD #if _LIBCPP_STD_VER > 14 -_LIBCPP_BEGIN_NAMESPACE_STD -namespace pmr { +_LIBCPP_BEGIN_NAMESPACE_STD_PMR template > -using map = std::map<_KeyT, _ValueT, _CompareT, polymorphic_allocator>>; +using map = std::map<_KeyT, _ValueT, _CompareT, std::pmr::polymorphic_allocator>>; template > -using multimap = std::multimap<_KeyT, _ValueT, _CompareT, polymorphic_allocator>>; -} // namespace pmr -_LIBCPP_END_NAMESPACE_STD +using multimap = std::multimap<_KeyT, _ValueT, _CompareT, std::pmr::polymorphic_allocator>>; +_LIBCPP_END_NAMESPACE_STD_PMR #endif #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 diff --git a/libcxx/include/regex b/libcxx/include/regex index 06c017fcce384..ac230d1fd6363 100644 --- a/libcxx/include/regex +++ b/libcxx/include/regex @@ -6845,10 +6845,9 @@ regex_replace(const _CharT* __s, _LIBCPP_END_NAMESPACE_STD #if _LIBCPP_STD_VER > 14 -_LIBCPP_BEGIN_NAMESPACE_STD -namespace pmr { +_LIBCPP_BEGIN_NAMESPACE_STD_PMR template -using match_results = std::match_results<_BidirT, polymorphic_allocator>>; +using match_results = std::match_results<_BidirT, std::pmr::polymorphic_allocator>>; using cmatch = match_results; using smatch = match_results; @@ -6857,8 +6856,7 @@ using smatch = match_results; using wcmatch = match_results; using wsmatch = match_results; #endif -} // namespace pmr -_LIBCPP_END_NAMESPACE_STD +_LIBCPP_END_NAMESPACE_STD_PMR #endif _LIBCPP_POP_MACROS diff --git a/libcxx/include/set b/libcxx/include/set index 1154c4e9509c7..fa95560a3d4ed 100644 --- a/libcxx/include/set +++ b/libcxx/include/set @@ -1585,15 +1585,13 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_END_NAMESPACE_STD #if _LIBCPP_STD_VER > 14 -_LIBCPP_BEGIN_NAMESPACE_STD -namespace pmr { +_LIBCPP_BEGIN_NAMESPACE_STD_PMR template > -using set = std::set<_KeyT, _CompareT, polymorphic_allocator<_KeyT>>; +using set = std::set<_KeyT, _CompareT, std::pmr::polymorphic_allocator<_KeyT>>; template > -using multiset = std::multiset<_KeyT, _CompareT, polymorphic_allocator<_KeyT>>; -} // namespace pmr -_LIBCPP_END_NAMESPACE_STD +using multiset = std::multiset<_KeyT, _CompareT, std::pmr::polymorphic_allocator<_KeyT>>; +_LIBCPP_END_NAMESPACE_STD_PMR #endif #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 diff --git a/libcxx/include/unordered_map b/libcxx/include/unordered_map index 14f93bab36e13..596bdd654654c 100644 --- a/libcxx/include/unordered_map +++ b/libcxx/include/unordered_map @@ -2630,17 +2630,15 @@ operator!=(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, _LIBCPP_END_NAMESPACE_STD #if _LIBCPP_STD_VER > 14 -_LIBCPP_BEGIN_NAMESPACE_STD -namespace pmr { +_LIBCPP_BEGIN_NAMESPACE_STD_PMR template , class _PredT = std::equal_to<_KeyT>> using unordered_map = - std::unordered_map<_KeyT, _ValueT, _HashT, _PredT, polymorphic_allocator>>; + std::unordered_map<_KeyT, _ValueT, _HashT, _PredT, std::pmr::polymorphic_allocator>>; template , class _PredT = std::equal_to<_KeyT>> using unordered_multimap = - std::unordered_multimap<_KeyT, _ValueT, _HashT, _PredT, polymorphic_allocator>>; -} // namespace pmr -_LIBCPP_END_NAMESPACE_STD + std::unordered_multimap<_KeyT, _ValueT, _HashT, _PredT, std::pmr::polymorphic_allocator>>; +_LIBCPP_END_NAMESPACE_STD_PMR #endif #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 diff --git a/libcxx/include/unordered_set b/libcxx/include/unordered_set index b4203c08a9b9b..dd9bd09ddbf67 100644 --- a/libcxx/include/unordered_set +++ b/libcxx/include/unordered_set @@ -1804,15 +1804,13 @@ operator!=(const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x, _LIBCPP_END_NAMESPACE_STD #if _LIBCPP_STD_VER > 14 -_LIBCPP_BEGIN_NAMESPACE_STD -namespace pmr { +_LIBCPP_BEGIN_NAMESPACE_STD_PMR template , class _PredT = std::equal_to<_KeyT>> -using unordered_set = std::unordered_set<_KeyT, _HashT, _PredT, polymorphic_allocator<_KeyT>>; +using unordered_set = std::unordered_set<_KeyT, _HashT, _PredT, std::pmr::polymorphic_allocator<_KeyT>>; template , class _PredT = std::equal_to<_KeyT>> -using unordered_multiset = std::unordered_multiset<_KeyT, _HashT, _PredT, polymorphic_allocator<_KeyT>>; -} // namespace pmr -_LIBCPP_END_NAMESPACE_STD +using unordered_multiset = std::unordered_multiset<_KeyT, _HashT, _PredT, std::pmr::polymorphic_allocator<_KeyT>>; +_LIBCPP_END_NAMESPACE_STD_PMR #endif #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 diff --git a/libcxx/include/vector b/libcxx/include/vector index bbf92145aa10d..f595a5cd74f12 100644 --- a/libcxx/include/vector +++ b/libcxx/include/vector @@ -302,7 +302,6 @@ erase_if(vector& c, Predicate pred); // C++20 #include <__utility/forward.h> #include <__utility/move.h> #include <__utility/swap.h> -#include <__utility/transaction.h> #include #include #include @@ -424,27 +423,18 @@ public: _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a); -private: - class __destroy_vector { - public: - _LIBCPP_CONSTEXPR __destroy_vector(vector& __vec) : __vec_(__vec) {} - - _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void operator()() { - __vec_.__annotate_delete(); - std::__debug_db_erase_c(std::addressof(__vec_)); + _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI + ~vector() + { + __annotate_delete(); + std::__debug_db_erase_c(this); - if (__vec_.__begin_ != nullptr) { - __vec_.__clear(); - __alloc_traits::deallocate(__vec_.__alloc(), __vec_.__begin_, __vec_.capacity()); - } + if (this->__begin_ != nullptr) + { + __clear(); + __alloc_traits::deallocate(__alloc(), this->__begin_, capacity()); } - - private: - vector& __vec_; - }; - -public: - _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI ~vector() { __destroy_vector(*this)(); } + } _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(const vector& __x); _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(const vector& __x, const __type_identity_t& __a); @@ -1064,14 +1054,12 @@ template _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(size_type __n) { - auto __guard = std::__make_transaction(__destroy_vector(*this)); std::__debug_db_insert_c(this); if (__n > 0) { __vallocate(__n); __construct_at_end(__n); } - __guard.__complete(); } #if _LIBCPP_STD_VER > 11 @@ -1080,14 +1068,12 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(size_type __n, const allocator_type& __a) : __end_cap_(nullptr, __a) { - auto __guard = std::__make_transaction(__destroy_vector(*this)); std::__debug_db_insert_c(this); if (__n > 0) { __vallocate(__n); __construct_at_end(__n); } - __guard.__complete(); } #endif @@ -1095,14 +1081,12 @@ template _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(size_type __n, const value_type& __x) { - auto __guard = std::__make_transaction(__destroy_vector(*this)); std::__debug_db_insert_c(this); if (__n > 0) { __vallocate(__n); __construct_at_end(__n, __x); } - __guard.__complete(); } template @@ -1112,11 +1096,9 @@ template ::vector(_InputIterator __first, _InputIterator __last) { - auto __guard = std::__make_transaction(__destroy_vector(*this)); std::__debug_db_insert_c(this); for (; __first != __last; ++__first) emplace_back(*__first); - __guard.__complete(); } template @@ -1127,11 +1109,9 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a) : __end_cap_(nullptr, __a) { - auto __guard = std::__make_transaction(__destroy_vector(*this)); std::__debug_db_insert_c(this); for (; __first != __last; ++__first) emplace_back(*__first); - __guard.__complete(); } template @@ -1141,7 +1121,6 @@ template ::vector(_ForwardIterator __first, _ForwardIterator __last) { - auto __guard = std::__make_transaction(__destroy_vector(*this)); std::__debug_db_insert_c(this); size_type __n = static_cast(std::distance(__first, __last)); if (__n > 0) @@ -1149,7 +1128,6 @@ vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __las __vallocate(__n); __construct_at_end(__first, __last, __n); } - __guard.__complete(); } template @@ -1160,7 +1138,6 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a) : __end_cap_(nullptr, __a) { - auto __guard = std::__make_transaction(__destroy_vector(*this)); std::__debug_db_insert_c(this); size_type __n = static_cast(std::distance(__first, __last)); if (__n > 0) @@ -1168,7 +1145,6 @@ vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __las __vallocate(__n); __construct_at_end(__first, __last, __n); } - __guard.__complete(); } template @@ -1176,7 +1152,6 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(const vector& __x) : __end_cap_(nullptr, __alloc_traits::select_on_container_copy_construction(__x.__alloc())) { - auto __guard = std::__make_transaction(__destroy_vector(*this)); std::__debug_db_insert_c(this); size_type __n = __x.size(); if (__n > 0) @@ -1184,7 +1159,6 @@ vector<_Tp, _Allocator>::vector(const vector& __x) __vallocate(__n); __construct_at_end(__x.__begin_, __x.__end_, __n); } - __guard.__complete(); } template @@ -1192,7 +1166,6 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(const vector& __x, const __type_identity_t& __a) : __end_cap_(nullptr, __a) { - auto __guard = std::__make_transaction(__destroy_vector(*this)); std::__debug_db_insert_c(this); size_type __n = __x.size(); if (__n > 0) @@ -1200,7 +1173,6 @@ vector<_Tp, _Allocator>::vector(const vector& __x, const __type_identity_t @@ -1240,9 +1212,7 @@ vector<_Tp, _Allocator>::vector(vector&& __x, const __type_identity_t _Ip; - auto __guard = std::__make_transaction(__destroy_vector(*this)); assign(_Ip(__x.begin()), _Ip(__x.end())); - __guard.__complete(); } } @@ -1253,14 +1223,12 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI vector<_Tp, _Allocator>::vector(initializer_list __il) { - auto __guard = std::__make_transaction(__destroy_vector(*this)); std::__debug_db_insert_c(this); if (__il.size() > 0) { __vallocate(__il.size()); __construct_at_end(__il.begin(), __il.end(), __il.size()); } - __guard.__complete(); } template @@ -1269,14 +1237,12 @@ inline _LIBCPP_HIDE_FROM_ABI vector<_Tp, _Allocator>::vector(initializer_list __il, const allocator_type& __a) : __end_cap_(nullptr, __a) { - auto __guard = std::__make_transaction(__destroy_vector(*this)); std::__debug_db_insert_c(this); if (__il.size() > 0) { __vallocate(__il.size()); __construct_at_end(__il.begin(), __il.end(), __il.size()); } - __guard.__complete(); } #endif // _LIBCPP_CXX03_LANG @@ -2094,25 +2060,7 @@ public: #else _NOEXCEPT; #endif - -private: - class __destroy_vector { - public: - _LIBCPP_CONSTEXPR __destroy_vector(vector& __vec) : __vec_(__vec) {} - - _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void operator()() { - if (__vec_.__begin_ != nullptr) - __storage_traits::deallocate(__vec_.__alloc(), __vec_.__begin_, __vec_.__cap()); - std::__debug_db_invalidate_all(this); - } - - private: - vector& __vec_; - }; - -public: - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 ~vector() { __destroy_vector(*this)(); } - + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 ~vector(); _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit vector(size_type __n); #if _LIBCPP_STD_VER > 11 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit vector(size_type __n, const allocator_type& __a); @@ -2648,14 +2596,12 @@ vector::vector(_ForwardIterator __first, _ForwardIterator __la __size_(0), __cap_alloc_(0, __default_init_tag()) { - auto __guard = std::__make_transaction(__destroy_vector(*this)); size_type __n = static_cast(std::distance(__first, __last)); if (__n > 0) { __vallocate(__n); __construct_at_end(__first, __last); } - __guard.__complete(); } template @@ -2667,14 +2613,12 @@ vector::vector(_ForwardIterator __first, _ForwardIterator __la __size_(0), __cap_alloc_(0, static_cast<__storage_allocator>(__a)) { - auto __guard = std::__make_transaction(__destroy_vector(*this)); size_type __n = static_cast(std::distance(__first, __last)); if (__n > 0) { __vallocate(__n); __construct_at_end(__first, __last); } - __guard.__complete(); } #ifndef _LIBCPP_CXX03_LANG @@ -2711,6 +2655,15 @@ vector::vector(initializer_list __il, const alloca #endif // _LIBCPP_CXX03_LANG +template +_LIBCPP_CONSTEXPR_SINCE_CXX20 +vector::~vector() +{ + if (__begin_ != nullptr) + __storage_traits::deallocate(__alloc(), __begin_, __cap()); + std::__debug_db_invalidate_all(this); +} + template _LIBCPP_CONSTEXPR_SINCE_CXX20 vector::vector(const vector& __v) @@ -3315,12 +3268,10 @@ inline constexpr bool __format::__enable_insertable> = true _LIBCPP_END_NAMESPACE_STD #if _LIBCPP_STD_VER > 14 -_LIBCPP_BEGIN_NAMESPACE_STD -namespace pmr { +_LIBCPP_BEGIN_NAMESPACE_STD_PMR template -using vector = std::vector<_ValueT, polymorphic_allocator<_ValueT>>; -} // namespace pmr -_LIBCPP_END_NAMESPACE_STD +using vector = std::vector<_ValueT, std::pmr::polymorphic_allocator<_ValueT>>; +_LIBCPP_END_NAMESPACE_STD_PMR #endif _LIBCPP_POP_MACROS diff --git a/libcxx/src/memory_resource.cpp b/libcxx/src/memory_resource.cpp index d4a735b4232c6..7daba159ecf74 100644 --- a/libcxx/src/memory_resource.cpp +++ b/libcxx/src/memory_resource.cpp @@ -18,7 +18,7 @@ # endif #endif -_LIBCPP_BEGIN_NAMESPACE_STD +namespace std { namespace pmr { @@ -476,4 +476,4 @@ void* monotonic_buffer_resource::do_allocate(size_t bytes, size_t align) { } // namespace pmr -_LIBCPP_END_NAMESPACE_STD +} From 454f1a149aef3cde3a935c6116dabb190ce5a8ca Mon Sep 17 00:00:00 2001 From: tbbdev Date: Sun, 18 Dec 2022 17:28:47 +0200 Subject: [PATCH 15/26] Add Microsoft STL compat layer --- libcxx/src/memory_resource.cpp | 112 +--------------- .../runtime/default_resource_fallback.ipp | 121 ++++++++++++++++++ .../support/runtime/default_resource_msvc.ipp | 64 +++++++++ 3 files changed, 191 insertions(+), 106 deletions(-) create mode 100644 libcxx/src/support/runtime/default_resource_fallback.ipp create mode 100644 libcxx/src/support/runtime/default_resource_msvc.ipp diff --git a/libcxx/src/memory_resource.cpp b/libcxx/src/memory_resource.cpp index 7daba159ecf74..6d0f723056ba9 100644 --- a/libcxx/src/memory_resource.cpp +++ b/libcxx/src/memory_resource.cpp @@ -9,6 +9,12 @@ #include #include +#if defined(_LIBCPP_ABI_MICROSOFT) +# include "support/runtime/default_resource_msvc.ipp" +#else +# include "support/runtime/default_resource_fallback.ipp" +#endif + #ifndef _LIBCPP_HAS_NO_ATOMIC_HEADER # include #elif !defined(_LIBCPP_HAS_NO_THREADS) @@ -26,112 +32,6 @@ namespace pmr { memory_resource::~memory_resource() = default; -// new_delete_resource() - -#ifdef _LIBCPP_HAS_NO_ALIGNED_ALLOCATION -static bool is_aligned_to(void* ptr, size_t align) { - void* p2 = ptr; - size_t space = 1; - void* result = std::align(align, 1, p2, space); - return (result == ptr); -} -#endif - -class _LIBCPP_TYPE_VIS __new_delete_memory_resource_imp : public memory_resource { - void* do_allocate(size_t bytes, size_t align) override { -#ifndef _LIBCPP_HAS_NO_ALIGNED_ALLOCATION - return std::__libcpp_allocate(bytes, align); -#else - if (bytes == 0) - bytes = 1; - void* result = std::__libcpp_allocate(bytes, align); - if (!is_aligned_to(result, align)) { - std::__libcpp_deallocate(result, bytes, align); - __throw_bad_alloc(); - } - return result; -#endif - } - - void do_deallocate(void* p, size_t bytes, size_t align) override { std::__libcpp_deallocate(p, bytes, align); } - - bool do_is_equal(const memory_resource& other) const noexcept override { return &other == this; } -}; - -// null_memory_resource() - -class _LIBCPP_TYPE_VIS __null_memory_resource_imp : public memory_resource { - void* do_allocate(size_t, size_t) override { __throw_bad_alloc(); } - void do_deallocate(void*, size_t, size_t) override {} - bool do_is_equal(const memory_resource& other) const noexcept override { return &other == this; } -}; - -namespace { - -union ResourceInitHelper { - struct { - __new_delete_memory_resource_imp new_delete_res; - __null_memory_resource_imp null_res; - } resources; - char dummy; - _LIBCPP_CONSTEXPR_SINCE_CXX14 ResourceInitHelper() : resources() {} - ~ResourceInitHelper() {} -}; - -// Pretend we're inside a system header so the compiler doesn't flag the use of the init_priority -// attribute with a value that's reserved for the implementation (we're the implementation). -#include "memory_resource_init_helper.h" - -} // end namespace - -memory_resource* new_delete_resource() noexcept { return &res_init.resources.new_delete_res; } - -memory_resource* null_memory_resource() noexcept { return &res_init.resources.null_res; } - -// default_memory_resource() - -static memory_resource* __default_memory_resource(bool set = false, memory_resource* new_res = nullptr) noexcept { -#ifndef _LIBCPP_HAS_NO_ATOMIC_HEADER - static constinit atomic __res{&res_init.resources.new_delete_res}; - if (set) { - new_res = new_res ? new_res : new_delete_resource(); - // TODO: Can a weaker ordering be used? - return std::atomic_exchange_explicit(&__res, new_res, memory_order_acq_rel); - } else { - return std::atomic_load_explicit(&__res, memory_order_acquire); - } -#elif !defined(_LIBCPP_HAS_NO_THREADS) - static constinit memory_resource* res = &res_init.resources.new_delete_res; - static mutex res_lock; - if (set) { - new_res = new_res ? new_res : new_delete_resource(); - lock_guard guard(res_lock); - memory_resource* old_res = res; - res = new_res; - return old_res; - } else { - lock_guard guard(res_lock); - return res; - } -#else - static constinit memory_resource* res = &res_init.resources.new_delete_res; - if (set) { - new_res = new_res ? new_res : new_delete_resource(); - memory_resource* old_res = res; - res = new_res; - return old_res; - } else { - return res; - } -#endif -} - -memory_resource* get_default_resource() noexcept { return __default_memory_resource(); } - -memory_resource* set_default_resource(memory_resource* __new_res) noexcept { - return __default_memory_resource(true, __new_res); -} - // 23.12.5, mem.res.pool static size_t roundup(size_t count, size_t alignment) { diff --git a/libcxx/src/support/runtime/default_resource_fallback.ipp b/libcxx/src/support/runtime/default_resource_fallback.ipp new file mode 100644 index 0000000000000..b700acf5f8113 --- /dev/null +++ b/libcxx/src/support/runtime/default_resource_fallback.ipp @@ -0,0 +1,121 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +namespace std { + +namespace pmr { + +// default_memory_resource() + +static memory_resource* __default_memory_resource(bool set = false, memory_resource* new_res = nullptr) noexcept { +#ifndef _LIBCPP_HAS_NO_ATOMIC_HEADER + static constinit atomic __res{&res_init.resources.new_delete_res}; + if (set) { + new_res = new_res ? new_res : new_delete_resource(); + // TODO: Can a weaker ordering be used? + return std::atomic_exchange_explicit(&__res, new_res, memory_order_acq_rel); + } else { + return std::atomic_load_explicit(&__res, memory_order_acquire); + } +#elif !defined(_LIBCPP_HAS_NO_THREADS) + static constinit memory_resource* res = &res_init.resources.new_delete_res; + static mutex res_lock; + if (set) { + new_res = new_res ? new_res : new_delete_resource(); + lock_guard guard(res_lock); + memory_resource* old_res = res; + res = new_res; + return old_res; + } else { + lock_guard guard(res_lock); + return res; + } +#else + static constinit memory_resource* res = &res_init.resources.new_delete_res; + if (set) { + new_res = new_res ? new_res : new_delete_resource(); + memory_resource* old_res = res; + res = new_res; + return old_res; + } else { + return res; + } +#endif +} + +memory_resource* get_default_resource() noexcept { return __default_memory_resource(); } + +memory_resource* set_default_resource(memory_resource* __new_res) noexcept { + return __default_memory_resource(true, __new_res); +} + +// new_delete_resource() + +#ifdef _LIBCPP_HAS_NO_ALIGNED_ALLOCATION +static bool is_aligned_to(void* ptr, size_t align) { + void* p2 = ptr; + size_t space = 1; + void* result = std::align(align, 1, p2, space); + return (result == ptr); +} +#endif + +class _LIBCPP_TYPE_VIS __new_delete_memory_resource_imp : public memory_resource { + void* do_allocate(size_t bytes, size_t align) override { +#ifndef _LIBCPP_HAS_NO_ALIGNED_ALLOCATION + return std::__libcpp_allocate(bytes, align); +#else + if (bytes == 0) + bytes = 1; + void* result = std::__libcpp_allocate(bytes, align); + if (!is_aligned_to(result, align)) { + std::__libcpp_deallocate(result, bytes, align); + __throw_bad_alloc(); + } + return result; +#endif + } + + void do_deallocate(void* p, size_t bytes, size_t align) override { std::__libcpp_deallocate(p, bytes, align); } + + bool do_is_equal(const memory_resource& other) const noexcept override { return &other == this; } +}; + +// null_memory_resource() + +class _LIBCPP_TYPE_VIS __null_memory_resource_imp : public memory_resource { + void* do_allocate(size_t, size_t) override { __throw_bad_alloc(); } + void do_deallocate(void*, size_t, size_t) override {} + bool do_is_equal(const memory_resource& other) const noexcept override { return &other == this; } +}; + +namespace { + +union ResourceInitHelper { + struct { + __new_delete_memory_resource_imp new_delete_res; + __null_memory_resource_imp null_res; + } resources; + char dummy; + _LIBCPP_CONSTEXPR_SINCE_CXX14 ResourceInitHelper() : resources() {} + ~ResourceInitHelper() {} +}; + +// Pretend we're inside a system header so the compiler doesn't flag the use of the init_priority +// attribute with a value that's reserved for the implementation (we're the implementation). +#include "memory_resource_init_helper.h" + +} // end namespace + +memory_resource* new_delete_resource() noexcept { return &res_init.resources.new_delete_res; } + +memory_resource* null_memory_resource() noexcept { return &res_init.resources.null_res; } + +} // pmr +} // std diff --git a/libcxx/src/support/runtime/default_resource_msvc.ipp b/libcxx/src/support/runtime/default_resource_msvc.ipp new file mode 100644 index 0000000000000..b7e041aa3adc3 --- /dev/null +++ b/libcxx/src/support/runtime/default_resource_msvc.ipp @@ -0,0 +1,64 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_ABI_MICROSOFT +#error this header can only be used when targeting the MSVC ABI +#endif + +// default_memory_resource() + +extern "C" { + +_LIBCPP_CRT_FUNC std::pmr::memory_resource* __cdecl _Aligned_set_default_resource(std::pmr::memory_resource*) noexcept; +_LIBCPP_CRT_FUNC std::pmr::memory_resource* __cdecl _Unaligned_set_default_resource(std::pmr::memory_resource*) noexcept; +_LIBCPP_CRT_FUNC std::pmr::memory_resource* __cdecl _Aligned_get_default_resource() noexcept; +_LIBCPP_CRT_FUNC std::pmr::memory_resource* __cdecl _Unaligned_get_default_resource() noexcept; +_LIBCPP_CRT_FUNC std::pmr::memory_resource* __cdecl _Aligned_new_delete_resource() noexcept; +_LIBCPP_CRT_FUNC std::pmr::memory_resource* __cdecl _Unaligned_new_delete_resource() noexcept; +_LIBCPP_CRT_FUNC std::pmr::memory_resource* __cdecl null_memory_resource() noexcept; + +}; + +namespace std { + +namespace pmr { + +memory_resource* get_default_resource() noexcept { + printf("Debug: compat get_default_resouce\n"); +#ifdef __cpp_aligned_new + return ::_Aligned_get_default_resource(); +#else + return ::_Unaligned_get_default_resource(); +#endif +} + +memory_resource* set_default_resource(memory_resource* __new_res) noexcept { + printf("Debug: compat set_default_resouce\n"); +#ifdef __cpp_aligned_new + return ::_Aligned_set_default_resource(__new_res); +#else + return ::_Unaligned_set_default_resource(__new_res); +#endif +} + +memory_resource* new_delete_resource() noexcept { +#ifdef __cpp_aligned_new + return ::_Aligned_new_delete_resource(); +#else + return ::_Unaligned_new_delete_resource(); +#endif +} + +memory_resource* null_memory_resource() noexcept { + return ::null_memory_resource(); +} + +} // pmr + +} // std From 8bea4fc8972ff75f2cc28beb4304130fb82bd065 Mon Sep 17 00:00:00 2001 From: tbbdev Date: Sun, 18 Dec 2022 17:40:35 +0200 Subject: [PATCH 16/26] Remove unnecessary things --- libcxx/include/__fwd/string.h | 2 - .../__memory_resource/polymorphic_allocator.h | 47 +++++- libcxx/include/vector | 134 +++++++++--------- libcxx/src/memory_resource.cpp | 2 +- .../runtime/default_resource_fallback.ipp | 4 +- .../support/runtime/default_resource_msvc.ipp | 4 +- 6 files changed, 121 insertions(+), 72 deletions(-) diff --git a/libcxx/include/__fwd/string.h b/libcxx/include/__fwd/string.h index a4ad4807ab574..6393d4430ad90 100644 --- a/libcxx/include/__fwd/string.h +++ b/libcxx/include/__fwd/string.h @@ -62,8 +62,6 @@ using u32string = basic_string; _LIBCPP_END_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD_PMR -using ___alloc = std::pmr::polymorphic_allocator; - template > using basic_string = std::basic_string<_CharT, _Traits, std::pmr::polymorphic_allocator<_CharT>>; diff --git a/libcxx/include/__memory_resource/polymorphic_allocator.h b/libcxx/include/__memory_resource/polymorphic_allocator.h index 2c69b33ed338b..c22b3b053192d 100644 --- a/libcxx/include/__memory_resource/polymorphic_allocator.h +++ b/libcxx/include/__memory_resource/polymorphic_allocator.h @@ -33,8 +33,13 @@ namespace pmr { // [mem.poly.allocator.class] -template +template = 20 + = byte +# endif + > class _LIBCPP_TEMPLATE_VIS polymorphic_allocator { + public: using value_type = _ValueType; @@ -66,6 +71,46 @@ class _LIBCPP_TEMPLATE_VIS polymorphic_allocator { __res_->deallocate(__p, __n * sizeof(_ValueType), alignof(_ValueType)); } +# if _LIBCPP_STD_VER >= 20 + + [[nodiscard]] [[using __gnu__: __alloc_size__(2), __alloc_align__(3)]] void* + allocate_bytes(size_t __nbytes, size_t __alignment = alignof(max_align_t)) { + return __res_->allocate(__nbytes, __alignment); + } + + void deallocate_bytes(void* __ptr, size_t __nbytes, size_t __alignment = alignof(max_align_t)) { + __res_->deallocate(__ptr, __nbytes, __alignment); + } + + template + [[nodiscard]] _Type* allocate_object(size_t __n = 1) { + if (numeric_limits::max() / sizeof(_Type) < __n) + std::__throw_bad_array_new_length(); + return static_cast<_Type*>(allocate_bytes(__n * sizeof(_Type), alignof(_Type))); + } + + template + void deallocate_object(_Type* __ptr, size_t __n = 1) { + deallocate_bytes(__ptr, __n * sizeof(_Type), alignof(_Type)); + } + + template + [[nodiscard]] _Type* new_object(_CtorArgs&&... __ctor_args) { + _Type* __ptr = allocate_object<_Type>(); + __transaction __guard([&] { deallocate_object(__ptr); }); + construct(__ptr, std::forward<_CtorArgs>(__ctor_args)...); + __guard.__complete(); + return __ptr; + } + + template + void delete_object(_Type* __ptr) { + destroy(__ptr); + deallocate_object(__ptr); + } + +# endif // _LIBCPP_STD_VER >= 20 + template _LIBCPP_HIDE_FROM_ABI void construct(_Tp* __p, _Ts&&... __args) { std::__user_alloc_construct_impl( diff --git a/libcxx/include/vector b/libcxx/include/vector index f595a5cd74f12..33f36e208f0ca 100644 --- a/libcxx/include/vector +++ b/libcxx/include/vector @@ -12,10 +12,8 @@ /* vector synopsis - namespace std { - template > class vector { @@ -32,7 +30,6 @@ public: typedef typename allocator_type::const_pointer const_pointer; typedef std::reverse_iterator reverse_iterator; typedef std::reverse_iterator const_reverse_iterator; - vector() noexcept(is_nothrow_default_constructible::value); explicit vector(const allocator_type&); @@ -57,50 +54,40 @@ public: void assign(InputIterator first, InputIterator last); void assign(size_type n, const value_type& u); void assign(initializer_list il); - allocator_type get_allocator() const noexcept; - iterator begin() noexcept; const_iterator begin() const noexcept; iterator end() noexcept; const_iterator end() const noexcept; - reverse_iterator rbegin() noexcept; const_reverse_iterator rbegin() const noexcept; reverse_iterator rend() noexcept; const_reverse_iterator rend() const noexcept; - const_iterator cbegin() const noexcept; const_iterator cend() const noexcept; const_reverse_iterator crbegin() const noexcept; const_reverse_iterator crend() const noexcept; - size_type size() const noexcept; size_type max_size() const noexcept; size_type capacity() const noexcept; bool empty() const noexcept; void reserve(size_type n); void shrink_to_fit() noexcept; - reference operator[](size_type n); const_reference operator[](size_type n) const; reference at(size_type n); const_reference at(size_type n) const; - reference front(); const_reference front() const; reference back(); const_reference back() const; - value_type* data() noexcept; const value_type* data() const noexcept; - void push_back(const value_type& x); void push_back(value_type&& x); template reference emplace_back(Args&&... args); // reference in C++17 void pop_back(); - template iterator emplace(const_iterator position, Args&&... args); iterator insert(const_iterator position, const value_type& x); iterator insert(const_iterator position, value_type&& x); @@ -108,22 +95,16 @@ public: template iterator insert(const_iterator position, InputIterator first, InputIterator last); iterator insert(const_iterator position, initializer_list il); - iterator erase(const_iterator position); iterator erase(const_iterator first, const_iterator last); - void clear() noexcept; - void resize(size_type sz); void resize(size_type sz, const value_type& c); - void swap(vector&) noexcept(allocator_traits::propagate_on_container_swap::value || allocator_traits::is_always_equal::value); // C++17 - bool __invariants() const; }; - template > class vector { @@ -138,7 +119,6 @@ public: typedef const_iterator const_pointer; typedef std::reverse_iterator reverse_iterator; typedef std::reverse_iterator const_reverse_iterator; - class reference { public: @@ -149,7 +129,6 @@ public: iterator operator&() const noexcept; void flip() noexcept; }; - class const_reference { public: @@ -157,7 +136,6 @@ public: operator bool() const noexcept; const_iterator operator&() const noexcept; }; - vector() noexcept(is_nothrow_default_constructible::value); explicit vector(const allocator_type&); @@ -181,94 +159,73 @@ public: void assign(InputIterator first, InputIterator last); void assign(size_type n, const value_type& u); void assign(initializer_list il); - allocator_type get_allocator() const noexcept; - iterator begin() noexcept; const_iterator begin() const noexcept; iterator end() noexcept; const_iterator end() const noexcept; - reverse_iterator rbegin() noexcept; const_reverse_iterator rbegin() const noexcept; reverse_iterator rend() noexcept; const_reverse_iterator rend() const noexcept; - const_iterator cbegin() const noexcept; const_iterator cend() const noexcept; const_reverse_iterator crbegin() const noexcept; const_reverse_iterator crend() const noexcept; - size_type size() const noexcept; size_type max_size() const noexcept; size_type capacity() const noexcept; bool empty() const noexcept; void reserve(size_type n); void shrink_to_fit() noexcept; - reference operator[](size_type n); const_reference operator[](size_type n) const; reference at(size_type n); const_reference at(size_type n) const; - reference front(); const_reference front() const; reference back(); const_reference back() const; - void push_back(const value_type& x); template reference emplace_back(Args&&... args); // C++14; reference in C++17 void pop_back(); - template iterator emplace(const_iterator position, Args&&... args); // C++14 iterator insert(const_iterator position, const value_type& x); iterator insert(const_iterator position, size_type n, const value_type& x); template iterator insert(const_iterator position, InputIterator first, InputIterator last); iterator insert(const_iterator position, initializer_list il); - iterator erase(const_iterator position); iterator erase(const_iterator first, const_iterator last); - void clear() noexcept; - void resize(size_type sz); void resize(size_type sz, value_type x); - void swap(vector&) noexcept(allocator_traits::propagate_on_container_swap::value || allocator_traits::is_always_equal::value); // C++17 void flip() noexcept; - bool __invariants() const; }; - template ::value_type>> vector(InputIterator, InputIterator, Allocator = Allocator()) -> vector::value_type, Allocator>; // C++17 - template struct hash>; - template bool operator==(const vector& x, const vector& y); template bool operator< (const vector& x, const vector& y); template bool operator!=(const vector& x, const vector& y); template bool operator> (const vector& x, const vector& y); template bool operator>=(const vector& x, const vector& y); template bool operator<=(const vector& x, const vector& y); - template void swap(vector& x, vector& y) noexcept(noexcept(x.swap(y))); - template typename vector::size_type erase(vector& c, const U& value); // C++20 template typename vector::size_type erase_if(vector& c, Predicate pred); // C++20 - } // std - */ #include <__algorithm/copy.h> @@ -302,6 +259,7 @@ erase_if(vector& c, Predicate pred); // C++20 #include <__utility/forward.h> #include <__utility/move.h> #include <__utility/swap.h> +#include <__utility/transaction.h> #include #include #include @@ -423,18 +381,27 @@ public: _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a); - _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI - ~vector() - { - __annotate_delete(); - std::__debug_db_erase_c(this); +private: + class __destroy_vector { + public: + _LIBCPP_CONSTEXPR __destroy_vector(vector& __vec) : __vec_(__vec) {} - if (this->__begin_ != nullptr) - { - __clear(); - __alloc_traits::deallocate(__alloc(), this->__begin_, capacity()); + _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void operator()() { + __vec_.__annotate_delete(); + std::__debug_db_erase_c(std::addressof(__vec_)); + + if (__vec_.__begin_ != nullptr) { + __vec_.__clear(); + __alloc_traits::deallocate(__vec_.__alloc(), __vec_.__begin_, __vec_.capacity()); + } } - } + + private: + vector& __vec_; + }; + +public: + _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI ~vector() { __destroy_vector(*this)(); } _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(const vector& __x); _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(const vector& __x, const __type_identity_t& __a); @@ -1054,12 +1021,14 @@ template _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(size_type __n) { + auto __guard = std::__make_transaction(__destroy_vector(*this)); std::__debug_db_insert_c(this); if (__n > 0) { __vallocate(__n); __construct_at_end(__n); } + __guard.__complete(); } #if _LIBCPP_STD_VER > 11 @@ -1068,12 +1037,14 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(size_type __n, const allocator_type& __a) : __end_cap_(nullptr, __a) { + auto __guard = std::__make_transaction(__destroy_vector(*this)); std::__debug_db_insert_c(this); if (__n > 0) { __vallocate(__n); __construct_at_end(__n); } + __guard.__complete(); } #endif @@ -1081,12 +1052,14 @@ template _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(size_type __n, const value_type& __x) { + auto __guard = std::__make_transaction(__destroy_vector(*this)); std::__debug_db_insert_c(this); if (__n > 0) { __vallocate(__n); __construct_at_end(__n, __x); } + __guard.__complete(); } template @@ -1096,9 +1069,11 @@ template ::vector(_InputIterator __first, _InputIterator __last) { + auto __guard = std::__make_transaction(__destroy_vector(*this)); std::__debug_db_insert_c(this); for (; __first != __last; ++__first) emplace_back(*__first); + __guard.__complete(); } template @@ -1109,9 +1084,11 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a) : __end_cap_(nullptr, __a) { + auto __guard = std::__make_transaction(__destroy_vector(*this)); std::__debug_db_insert_c(this); for (; __first != __last; ++__first) emplace_back(*__first); + __guard.__complete(); } template @@ -1121,6 +1098,7 @@ template ::vector(_ForwardIterator __first, _ForwardIterator __last) { + auto __guard = std::__make_transaction(__destroy_vector(*this)); std::__debug_db_insert_c(this); size_type __n = static_cast(std::distance(__first, __last)); if (__n > 0) @@ -1128,6 +1106,7 @@ vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __las __vallocate(__n); __construct_at_end(__first, __last, __n); } + __guard.__complete(); } template @@ -1138,6 +1117,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a) : __end_cap_(nullptr, __a) { + auto __guard = std::__make_transaction(__destroy_vector(*this)); std::__debug_db_insert_c(this); size_type __n = static_cast(std::distance(__first, __last)); if (__n > 0) @@ -1145,6 +1125,7 @@ vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __las __vallocate(__n); __construct_at_end(__first, __last, __n); } + __guard.__complete(); } template @@ -1152,6 +1133,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(const vector& __x) : __end_cap_(nullptr, __alloc_traits::select_on_container_copy_construction(__x.__alloc())) { + auto __guard = std::__make_transaction(__destroy_vector(*this)); std::__debug_db_insert_c(this); size_type __n = __x.size(); if (__n > 0) @@ -1159,6 +1141,7 @@ vector<_Tp, _Allocator>::vector(const vector& __x) __vallocate(__n); __construct_at_end(__x.__begin_, __x.__end_, __n); } + __guard.__complete(); } template @@ -1166,6 +1149,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(const vector& __x, const __type_identity_t& __a) : __end_cap_(nullptr, __a) { + auto __guard = std::__make_transaction(__destroy_vector(*this)); std::__debug_db_insert_c(this); size_type __n = __x.size(); if (__n > 0) @@ -1173,6 +1157,7 @@ vector<_Tp, _Allocator>::vector(const vector& __x, const __type_identity_t @@ -1212,7 +1197,9 @@ vector<_Tp, _Allocator>::vector(vector&& __x, const __type_identity_t _Ip; + auto __guard = std::__make_transaction(__destroy_vector(*this)); assign(_Ip(__x.begin()), _Ip(__x.end())); + __guard.__complete(); } } @@ -1223,12 +1210,14 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI vector<_Tp, _Allocator>::vector(initializer_list __il) { + auto __guard = std::__make_transaction(__destroy_vector(*this)); std::__debug_db_insert_c(this); if (__il.size() > 0) { __vallocate(__il.size()); __construct_at_end(__il.begin(), __il.end(), __il.size()); } + __guard.__complete(); } template @@ -1237,12 +1226,14 @@ inline _LIBCPP_HIDE_FROM_ABI vector<_Tp, _Allocator>::vector(initializer_list __il, const allocator_type& __a) : __end_cap_(nullptr, __a) { + auto __guard = std::__make_transaction(__destroy_vector(*this)); std::__debug_db_insert_c(this); if (__il.size() > 0) { __vallocate(__il.size()); __construct_at_end(__il.begin(), __il.end(), __il.size()); } + __guard.__complete(); } #endif // _LIBCPP_CXX03_LANG @@ -2060,7 +2051,25 @@ public: #else _NOEXCEPT; #endif - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 ~vector(); + +private: + class __destroy_vector { + public: + _LIBCPP_CONSTEXPR __destroy_vector(vector& __vec) : __vec_(__vec) {} + + _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void operator()() { + if (__vec_.__begin_ != nullptr) + __storage_traits::deallocate(__vec_.__alloc(), __vec_.__begin_, __vec_.__cap()); + std::__debug_db_invalidate_all(this); + } + + private: + vector& __vec_; + }; + +public: + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 ~vector() { __destroy_vector(*this)(); } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit vector(size_type __n); #if _LIBCPP_STD_VER > 11 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit vector(size_type __n, const allocator_type& __a); @@ -2596,12 +2605,14 @@ vector::vector(_ForwardIterator __first, _ForwardIterator __la __size_(0), __cap_alloc_(0, __default_init_tag()) { + auto __guard = std::__make_transaction(__destroy_vector(*this)); size_type __n = static_cast(std::distance(__first, __last)); if (__n > 0) { __vallocate(__n); __construct_at_end(__first, __last); } + __guard.__complete(); } template @@ -2613,12 +2624,14 @@ vector::vector(_ForwardIterator __first, _ForwardIterator __la __size_(0), __cap_alloc_(0, static_cast<__storage_allocator>(__a)) { + auto __guard = std::__make_transaction(__destroy_vector(*this)); size_type __n = static_cast(std::distance(__first, __last)); if (__n > 0) { __vallocate(__n); __construct_at_end(__first, __last); } + __guard.__complete(); } #ifndef _LIBCPP_CXX03_LANG @@ -2655,15 +2668,6 @@ vector::vector(initializer_list __il, const alloca #endif // _LIBCPP_CXX03_LANG -template -_LIBCPP_CONSTEXPR_SINCE_CXX20 -vector::~vector() -{ - if (__begin_ != nullptr) - __storage_traits::deallocate(__alloc(), __begin_, __cap()); - std::__debug_db_invalidate_all(this); -} - template _LIBCPP_CONSTEXPR_SINCE_CXX20 vector::vector(const vector& __v) @@ -3269,8 +3273,10 @@ _LIBCPP_END_NAMESPACE_STD #if _LIBCPP_STD_VER > 14 _LIBCPP_BEGIN_NAMESPACE_STD_PMR +namespace pmr { template using vector = std::vector<_ValueT, std::pmr::polymorphic_allocator<_ValueT>>; +} // namespace pmr _LIBCPP_END_NAMESPACE_STD_PMR #endif @@ -3284,4 +3290,4 @@ _LIBCPP_POP_MACROS # include #endif -#endif // _LIBCPP_VECTOR +#endif // _LIBCPP_VECTOR \ No newline at end of file diff --git a/libcxx/src/memory_resource.cpp b/libcxx/src/memory_resource.cpp index 6d0f723056ba9..aca46ff6c7504 100644 --- a/libcxx/src/memory_resource.cpp +++ b/libcxx/src/memory_resource.cpp @@ -376,4 +376,4 @@ void* monotonic_buffer_resource::do_allocate(size_t bytes, size_t align) { } // namespace pmr -} +} // namespace std diff --git a/libcxx/src/support/runtime/default_resource_fallback.ipp b/libcxx/src/support/runtime/default_resource_fallback.ipp index b700acf5f8113..9685c498b20c7 100644 --- a/libcxx/src/support/runtime/default_resource_fallback.ipp +++ b/libcxx/src/support/runtime/default_resource_fallback.ipp @@ -117,5 +117,5 @@ memory_resource* new_delete_resource() noexcept { return &res_init.resources.new memory_resource* null_memory_resource() noexcept { return &res_init.resources.null_res; } -} // pmr -} // std +} // namespace pmr +} // namespace std diff --git a/libcxx/src/support/runtime/default_resource_msvc.ipp b/libcxx/src/support/runtime/default_resource_msvc.ipp index b7e041aa3adc3..96b25434deef4 100644 --- a/libcxx/src/support/runtime/default_resource_msvc.ipp +++ b/libcxx/src/support/runtime/default_resource_msvc.ipp @@ -59,6 +59,6 @@ memory_resource* null_memory_resource() noexcept { return ::null_memory_resource(); } -} // pmr +} // namespace pmr -} // std +} // namespace std From 4b3bfbb2ee8350582599dc346ba052f10775a6b3 Mon Sep 17 00:00:00 2001 From: tbbdev Date: Sun, 18 Dec 2022 17:43:55 +0200 Subject: [PATCH 17/26] +newline --- libcxx/include/vector | 2 +- libcxx/src/{ => support/runtime}/memory_resource_init_helper.h | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename libcxx/src/{ => support/runtime}/memory_resource_init_helper.h (100%) diff --git a/libcxx/include/vector b/libcxx/include/vector index 33f36e208f0ca..d1277b94e0f64 100644 --- a/libcxx/include/vector +++ b/libcxx/include/vector @@ -3290,4 +3290,4 @@ _LIBCPP_POP_MACROS # include #endif -#endif // _LIBCPP_VECTOR \ No newline at end of file +#endif // _LIBCPP_VECTOR diff --git a/libcxx/src/memory_resource_init_helper.h b/libcxx/src/support/runtime/memory_resource_init_helper.h similarity index 100% rename from libcxx/src/memory_resource_init_helper.h rename to libcxx/src/support/runtime/memory_resource_init_helper.h From b6578dd716cc351d5db3b03839995136e3360f45 Mon Sep 17 00:00:00 2001 From: tbbdev Date: Sun, 18 Dec 2022 17:44:57 +0200 Subject: [PATCH 18/26] Whitespace fix --- libcxx/src/memory_resource.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libcxx/src/memory_resource.cpp b/libcxx/src/memory_resource.cpp index aca46ff6c7504..8ac49a0f47706 100644 --- a/libcxx/src/memory_resource.cpp +++ b/libcxx/src/memory_resource.cpp @@ -10,9 +10,9 @@ #include #if defined(_LIBCPP_ABI_MICROSOFT) -# include "support/runtime/default_resource_msvc.ipp" +# include "support/runtime/default_resource_msvc.ipp" #else -# include "support/runtime/default_resource_fallback.ipp" +# include "support/runtime/default_resource_fallback.ipp" #endif #ifndef _LIBCPP_HAS_NO_ATOMIC_HEADER From f921db133be24625bb16babca5f1bf1536156ff8 Mon Sep 17 00:00:00 2001 From: tbbdev Date: Sun, 18 Dec 2022 18:43:42 +0200 Subject: [PATCH 19/26] Rename compat layer files --- libcxx/src/memory_resource.cpp | 4 ++-- ...ult_resource_fallback.ipp => memory_resource_fallback.ipp} | 0 .../{default_resource_msvc.ipp => memory_resource_msvc.ipp} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename libcxx/src/support/runtime/{default_resource_fallback.ipp => memory_resource_fallback.ipp} (100%) rename libcxx/src/support/runtime/{default_resource_msvc.ipp => memory_resource_msvc.ipp} (100%) diff --git a/libcxx/src/memory_resource.cpp b/libcxx/src/memory_resource.cpp index 8ac49a0f47706..8ce0ad4d3894b 100644 --- a/libcxx/src/memory_resource.cpp +++ b/libcxx/src/memory_resource.cpp @@ -10,9 +10,9 @@ #include #if defined(_LIBCPP_ABI_MICROSOFT) -# include "support/runtime/default_resource_msvc.ipp" +# include "support/runtime/memory_resource_msvc.ipp" #else -# include "support/runtime/default_resource_fallback.ipp" +# include "support/runtime/memory_resource_fallback.ipp" #endif #ifndef _LIBCPP_HAS_NO_ATOMIC_HEADER diff --git a/libcxx/src/support/runtime/default_resource_fallback.ipp b/libcxx/src/support/runtime/memory_resource_fallback.ipp similarity index 100% rename from libcxx/src/support/runtime/default_resource_fallback.ipp rename to libcxx/src/support/runtime/memory_resource_fallback.ipp diff --git a/libcxx/src/support/runtime/default_resource_msvc.ipp b/libcxx/src/support/runtime/memory_resource_msvc.ipp similarity index 100% rename from libcxx/src/support/runtime/default_resource_msvc.ipp rename to libcxx/src/support/runtime/memory_resource_msvc.ipp From 93196d7072203f93fd2c891ebbd8a26d7a43d852 Mon Sep 17 00:00:00 2001 From: kboyarinov Date: Thu, 22 Dec 2022 09:51:20 -0600 Subject: [PATCH 20/26] Broken: remove unnecessary macros from config --- libcxx/include/__config | 2 -- 1 file changed, 2 deletions(-) diff --git a/libcxx/include/__config b/libcxx/include/__config index 110036f947e51..505ccf95de724 100644 --- a/libcxx/include/__config +++ b/libcxx/include/__config @@ -647,9 +647,7 @@ typedef __char32_t char32_t; // Inline namespaces are available in Clang/GCC/MSVC regardless of C++ dialect. // clang-format off # define _LIBCPP_BEGIN_NAMESPACE_STD namespace std { inline namespace _LIBCPP_ABI_NAMESPACE { -# define _LIBCPP_BEGIN_NAMESPACE_STD_PMR namespace std { namespace pmr { inline namespace _LIBCPP_ABI_NAMESPACE { # define _LIBCPP_END_NAMESPACE_STD }} -# define _LIBCPP_END_NAMESPACE_STD_PMR }}} # define _VSTD std _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD From 8be4659c906df7d9d698af89694ca9be52f18f20 Mon Sep 17 00:00:00 2001 From: kboyarinov Date: Thu, 22 Dec 2022 09:59:05 -0600 Subject: [PATCH 21/26] Broken: minor fixes in __fwd --- libcxx/include/__fwd/memory_resource.h | 2 +- libcxx/include/__fwd/string.h | 53 +++++++++++++------------- 2 files changed, 28 insertions(+), 27 deletions(-) diff --git a/libcxx/include/__fwd/memory_resource.h b/libcxx/include/__fwd/memory_resource.h index a8f71e5270dbd..b6c85d8d69d30 100644 --- a/libcxx/include/__fwd/memory_resource.h +++ b/libcxx/include/__fwd/memory_resource.h @@ -22,6 +22,6 @@ template class _LIBCPP_TEMPLATE_VIS polymorphic_allocator; } // namespace pmr -} +} // namespace std #endif // _LIBCPP___FWD_MEMORY_RESOURCE_H diff --git a/libcxx/include/__fwd/string.h b/libcxx/include/__fwd/string.h index 6393d4430ad90..234b7767e0497 100644 --- a/libcxx/include/__fwd/string.h +++ b/libcxx/include/__fwd/string.h @@ -57,32 +57,6 @@ using u8string = basic_string; using u16string = basic_string; using u32string = basic_string; -#if _LIBCPP_STD_VER >= 17 - -_LIBCPP_END_NAMESPACE_STD -_LIBCPP_BEGIN_NAMESPACE_STD_PMR - -template > -using basic_string = std::basic_string<_CharT, _Traits, std::pmr::polymorphic_allocator<_CharT>>; - -using string = basic_string; - -# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS -using wstring = basic_string; -# endif - -# ifndef _LIBCPP_HAS_NO_CHAR8_T -using u8string = basic_string; -# endif - -using u16string = basic_string; -using u32string = basic_string; - -_LIBCPP_END_NAMESPACE_STD_PMR -_LIBCPP_BEGIN_NAMESPACE_STD - -#endif // _LIBCPP_STD_VER >= 17 - // clang-format off template class _LIBCPP_PREFERRED_NAME(string) @@ -110,4 +84,31 @@ class _LIBCPP_PREFERRED_NAME(string) _LIBCPP_END_NAMESPACE_STD +#if _LIBCPP_STD_VER >= 17 + +namespace std { +namespace pmr { + +template > +using basic_string = std::basic_string<_CharT, _Traits, std::pmr::polymorphic_allocator<_CharT>>; + +using string = basic_string; + +# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +using wstring = basic_string; +# endif + +# ifndef _LIBCPP_HAS_NO_CHAR8_T +using u8string = basic_string; +# endif + +using u16string = basic_string; +using u32string = basic_string; + +} // namespace pmr + +} // namespace std + +#endif // _LIBCPP_STD_VER >= 17 + #endif // _LIBCPP___FWD_STRING_H From 85b3f5aa3b101ea27d3fe9bdaf5ed52fbf9e801b Mon Sep 17 00:00:00 2001 From: kboyarinov Date: Thu, 22 Dec 2022 10:49:22 -0600 Subject: [PATCH 22/26] Working: minor cosmetic changes --- libcxx/include/__fwd/memory_resource.h | 2 +- libcxx/include/__fwd/string.h | 2 +- libcxx/include/__memory_resource/memory_resource.h | 3 +-- .../__memory_resource/monotonic_buffer_resource.h | 4 ++-- .../__memory_resource/polymorphic_allocator.h | 5 +++-- libcxx/include/__memory_resource/pool_options.h | 4 ++-- .../__memory_resource/synchronized_pool_resource.h | 4 ++-- .../unsynchronized_pool_resource.h | 4 ++-- libcxx/include/deque | 13 ++++++++++--- libcxx/include/experimental/deque | 2 +- libcxx/include/experimental/forward_list | 2 +- libcxx/include/experimental/list | 2 +- libcxx/include/experimental/map | 4 ++-- libcxx/include/forward_list | 12 ++++++++++-- libcxx/include/list | 12 ++++++++++-- libcxx/include/map | 12 ++++++++++-- libcxx/include/regex | 12 ++++++++++-- libcxx/include/set | 12 ++++++++++-- libcxx/include/unordered_map | 12 ++++++++++-- libcxx/include/unordered_set | 12 ++++++++++-- libcxx/include/vector | 10 ++++++++-- libcxx/src/support/runtime/memory_resource_msvc.ipp | 2 -- 22 files changed, 107 insertions(+), 40 deletions(-) diff --git a/libcxx/include/__fwd/memory_resource.h b/libcxx/include/__fwd/memory_resource.h index b6c85d8d69d30..b280858befce2 100644 --- a/libcxx/include/__fwd/memory_resource.h +++ b/libcxx/include/__fwd/memory_resource.h @@ -15,7 +15,7 @@ # pragma GCC system_header #endif -namespace std { // purposefully not using versioning namespace +namespace std { // purposefully not using versioning namespace namespace pmr { template diff --git a/libcxx/include/__fwd/string.h b/libcxx/include/__fwd/string.h index 234b7767e0497..ea7cb25c56a9d 100644 --- a/libcxx/include/__fwd/string.h +++ b/libcxx/include/__fwd/string.h @@ -90,7 +90,7 @@ namespace std { namespace pmr { template > -using basic_string = std::basic_string<_CharT, _Traits, std::pmr::polymorphic_allocator<_CharT>>; +using basic_string = std::basic_string<_CharT, _Traits, polymorphic_allocator<_CharT>>; using string = basic_string; diff --git a/libcxx/include/__memory_resource/memory_resource.h b/libcxx/include/__memory_resource/memory_resource.h index cedf53d15f13e..1dfe4c45b3e05 100644 --- a/libcxx/include/__memory_resource/memory_resource.h +++ b/libcxx/include/__memory_resource/memory_resource.h @@ -18,8 +18,7 @@ #if _LIBCPP_STD_VER > 14 -namespace std // purposefully not using versioning namespace -{ +namespace std { // purposefully not using versioning namespace namespace pmr { diff --git a/libcxx/include/__memory_resource/monotonic_buffer_resource.h b/libcxx/include/__memory_resource/monotonic_buffer_resource.h index 3fa7473bfc5cd..a663a777a6de2 100644 --- a/libcxx/include/__memory_resource/monotonic_buffer_resource.h +++ b/libcxx/include/__memory_resource/monotonic_buffer_resource.h @@ -20,7 +20,7 @@ #if _LIBCPP_STD_VER > 14 -namespace std { // purposefully not using versioning namespace +namespace std { // purposefully not using versioning namespace namespace pmr { @@ -112,7 +112,7 @@ class _LIBCPP_TYPE_VIS monotonic_buffer_resource : public memory_resource { } // namespace pmr -} +} // namespace std #endif // _LIBCPP_STD_VER > 14 diff --git a/libcxx/include/__memory_resource/polymorphic_allocator.h b/libcxx/include/__memory_resource/polymorphic_allocator.h index c22b3b053192d..b5b067d255fe1 100644 --- a/libcxx/include/__memory_resource/polymorphic_allocator.h +++ b/libcxx/include/__memory_resource/polymorphic_allocator.h @@ -12,6 +12,7 @@ #include <__assert> #include <__config> #include <__memory_resource/memory_resource.h> +#include <__utility/transaction.h> #include #include #include @@ -27,7 +28,7 @@ _LIBCPP_PUSH_MACROS #if _LIBCPP_STD_VER > 14 -namespace std { // purposefully not using versioning namespace +namespace std { // purposefully not using versioning namespace namespace pmr { @@ -214,7 +215,7 @@ operator!=(const polymorphic_allocator<_Tp>& __lhs, const polymorphic_allocator< } // namespace pmr -} +} // namespace std #endif // _LIBCPP_STD_VER > 14 diff --git a/libcxx/include/__memory_resource/pool_options.h b/libcxx/include/__memory_resource/pool_options.h index 60cebc4c0d844..ac9600ed8e564 100644 --- a/libcxx/include/__memory_resource/pool_options.h +++ b/libcxx/include/__memory_resource/pool_options.h @@ -18,7 +18,7 @@ #if _LIBCPP_STD_VER > 14 -namespace std { // purposefully not using versioning namespace +namespace std { // purposefully not using versioning namespace namespace pmr { @@ -31,7 +31,7 @@ struct _LIBCPP_TYPE_VIS pool_options { } // namespace pmr -} +} // namespace std #endif // _LIBCPP_STD_VER > 14 diff --git a/libcxx/include/__memory_resource/synchronized_pool_resource.h b/libcxx/include/__memory_resource/synchronized_pool_resource.h index 18b53f79f713e..218ae3342123a 100644 --- a/libcxx/include/__memory_resource/synchronized_pool_resource.h +++ b/libcxx/include/__memory_resource/synchronized_pool_resource.h @@ -24,7 +24,7 @@ #if _LIBCPP_STD_VER > 14 -namespace std { // purposefully not using versioning namespace +namespace std { // purposefully not using versioning namespace namespace pmr { @@ -87,7 +87,7 @@ class _LIBCPP_TYPE_VIS synchronized_pool_resource : public memory_resource { } // namespace pmr -} +} // namespace std #endif // _LIBCPP_STD_VER > 14 diff --git a/libcxx/include/__memory_resource/unsynchronized_pool_resource.h b/libcxx/include/__memory_resource/unsynchronized_pool_resource.h index 281f053d076ef..cd354dcc73e08 100644 --- a/libcxx/include/__memory_resource/unsynchronized_pool_resource.h +++ b/libcxx/include/__memory_resource/unsynchronized_pool_resource.h @@ -21,7 +21,7 @@ #if _LIBCPP_STD_VER > 14 -namespace std { // purposefully not using versioning namespace +namespace std { // purposefully not using versioning namespace namespace pmr { @@ -99,7 +99,7 @@ class _LIBCPP_TYPE_VIS unsynchronized_pool_resource : public memory_resource { } // namespace pmr -} +} // namespace std #endif // _LIBCPP_STD_VER > 14 diff --git a/libcxx/include/deque b/libcxx/include/deque index a35fd2d182366..e3baf114e3a32 100644 --- a/libcxx/include/deque +++ b/libcxx/include/deque @@ -2932,10 +2932,17 @@ inline constexpr bool __format::__enable_insertable> = true; _LIBCPP_END_NAMESPACE_STD #if _LIBCPP_STD_VER > 14 -_LIBCPP_BEGIN_NAMESPACE_STD_PMR +namespace std { + +namespace pmr { + template -using deque = std::deque<_ValueT, std::pmr::polymorphic_allocator<_ValueT>>; -_LIBCPP_END_NAMESPACE_STD_PMR +using deque = std::deque<_ValueT, polymorphic_allocator<_ValueT>>; + +} // namespace pmr + +} // namespace std + #endif _LIBCPP_POP_MACROS diff --git a/libcxx/include/experimental/deque b/libcxx/include/experimental/deque index 430b31d7447dd..46962afbb795e 100644 --- a/libcxx/include/experimental/deque +++ b/libcxx/include/experimental/deque @@ -43,7 +43,7 @@ _LIBCPP_BEGIN_NAMESPACE_LFTS_PMR #ifndef _LIBCPP_CXX03_LANG template -using deque = _VSTD::deque<_ValueT, std::pmr::polymorphic_allocator<_ValueT>>; +using deque = _VSTD::deque<_ValueT, polymorphic_allocator<_ValueT>>; #endif // _LIBCPP_CXX03_LANG diff --git a/libcxx/include/experimental/forward_list b/libcxx/include/experimental/forward_list index 59886d7eb458e..5d2686deb2768 100644 --- a/libcxx/include/experimental/forward_list +++ b/libcxx/include/experimental/forward_list @@ -43,7 +43,7 @@ _LIBCPP_BEGIN_NAMESPACE_LFTS_PMR #ifndef _LIBCPP_CXX03_LANG template -using forward_list = _VSTD::forward_list<_ValueT, std::pmr::polymorphic_allocator<_ValueT>>; +using forward_list = _VSTD::forward_list<_ValueT, polymorphic_allocator<_ValueT>>; #endif // _LIBCPP_CXX03_LANG diff --git a/libcxx/include/experimental/list b/libcxx/include/experimental/list index 62d7f59e95a67..06abe8702241e 100644 --- a/libcxx/include/experimental/list +++ b/libcxx/include/experimental/list @@ -43,7 +43,7 @@ _LIBCPP_BEGIN_NAMESPACE_LFTS_PMR #ifndef _LIBCPP_CXX03_LANG template -using list = _VSTD::list<_ValueT, std::pmr::polymorphic_allocator<_ValueT>>; +using list = _VSTD::list<_ValueT, polymorphic_allocator<_ValueT>>; #endif // _LIBCPP_CXX03_LANG diff --git a/libcxx/include/experimental/map b/libcxx/include/experimental/map index 5730562801519..8ec94e4a5bc86 100644 --- a/libcxx/include/experimental/map +++ b/libcxx/include/experimental/map @@ -49,11 +49,11 @@ _LIBCPP_BEGIN_NAMESPACE_LFTS_PMR template > using map = _VSTD::map<_Key, _Value, _Compare, - std::pmr::polymorphic_allocator>>; + polymorphic_allocator>>; template > using multimap = _VSTD::multimap<_Key, _Value, _Compare, - std::pmr::polymorphic_allocator>>; + polymorphic_allocator>>; #endif // _LIBCPP_CXX03_LANG diff --git a/libcxx/include/forward_list b/libcxx/include/forward_list index d3ae6073d44b8..ac441b422df1a 100644 --- a/libcxx/include/forward_list +++ b/libcxx/include/forward_list @@ -1780,10 +1780,18 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_END_NAMESPACE_STD #if _LIBCPP_STD_VER > 14 -_LIBCPP_BEGIN_NAMESPACE_STD_PMR + +namespace std { + +namespace pmr { + template using forward_list = std::forward_list<_ValueT, std::pmr::polymorphic_allocator<_ValueT>>; -_LIBCPP_END_NAMESPACE_STD_PMR + +} // namespace pmr + +} // namespace std + #endif _LIBCPP_POP_MACROS diff --git a/libcxx/include/list b/libcxx/include/list index c25c24aa551b5..027b1cbb1c0dc 100644 --- a/libcxx/include/list +++ b/libcxx/include/list @@ -2363,10 +2363,18 @@ inline constexpr bool __format::__enable_insertable> = true; _LIBCPP_END_NAMESPACE_STD #if _LIBCPP_STD_VER > 14 -_LIBCPP_BEGIN_NAMESPACE_STD_PMR + +namespace std { + +namespace pmr { + template using list = std::list<_ValueT, std::pmr::polymorphic_allocator<_ValueT>>; -_LIBCPP_END_NAMESPACE_STD_PMR + +} // namespace pmr + +} // namespace std + #endif _LIBCPP_POP_MACROS diff --git a/libcxx/include/map b/libcxx/include/map index 580693e58c68d..df3da627680ef 100644 --- a/libcxx/include/map +++ b/libcxx/include/map @@ -2340,13 +2340,21 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_END_NAMESPACE_STD #if _LIBCPP_STD_VER > 14 -_LIBCPP_BEGIN_NAMESPACE_STD_PMR + +namespace std { + +namespace pmr { + template > using map = std::map<_KeyT, _ValueT, _CompareT, std::pmr::polymorphic_allocator>>; template > using multimap = std::multimap<_KeyT, _ValueT, _CompareT, std::pmr::polymorphic_allocator>>; -_LIBCPP_END_NAMESPACE_STD_PMR + +} // namespace pmr + +} // namespace std + #endif #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 diff --git a/libcxx/include/regex b/libcxx/include/regex index ac230d1fd6363..8527cee3388d7 100644 --- a/libcxx/include/regex +++ b/libcxx/include/regex @@ -6845,7 +6845,11 @@ regex_replace(const _CharT* __s, _LIBCPP_END_NAMESPACE_STD #if _LIBCPP_STD_VER > 14 -_LIBCPP_BEGIN_NAMESPACE_STD_PMR + +namespace std { + +namespace pmr { + template using match_results = std::match_results<_BidirT, std::pmr::polymorphic_allocator>>; @@ -6856,7 +6860,11 @@ using smatch = match_results; using wcmatch = match_results; using wsmatch = match_results; #endif -_LIBCPP_END_NAMESPACE_STD_PMR + +} // namespace pmr + +} // namespace std + #endif _LIBCPP_POP_MACROS diff --git a/libcxx/include/set b/libcxx/include/set index fa95560a3d4ed..da8c8d1ce3d99 100644 --- a/libcxx/include/set +++ b/libcxx/include/set @@ -1585,13 +1585,21 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_END_NAMESPACE_STD #if _LIBCPP_STD_VER > 14 -_LIBCPP_BEGIN_NAMESPACE_STD_PMR + +namespace std { + +namespace pmr { + template > using set = std::set<_KeyT, _CompareT, std::pmr::polymorphic_allocator<_KeyT>>; template > using multiset = std::multiset<_KeyT, _CompareT, std::pmr::polymorphic_allocator<_KeyT>>; -_LIBCPP_END_NAMESPACE_STD_PMR + +} // namespace pmr + +} // namespace std + #endif #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 diff --git a/libcxx/include/unordered_map b/libcxx/include/unordered_map index 596bdd654654c..7b176a1e5ed65 100644 --- a/libcxx/include/unordered_map +++ b/libcxx/include/unordered_map @@ -2630,7 +2630,11 @@ operator!=(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, _LIBCPP_END_NAMESPACE_STD #if _LIBCPP_STD_VER > 14 -_LIBCPP_BEGIN_NAMESPACE_STD_PMR + +namespace std { + +namespace pmr { + template , class _PredT = std::equal_to<_KeyT>> using unordered_map = std::unordered_map<_KeyT, _ValueT, _HashT, _PredT, std::pmr::polymorphic_allocator>>; @@ -2638,7 +2642,11 @@ using unordered_map = template , class _PredT = std::equal_to<_KeyT>> using unordered_multimap = std::unordered_multimap<_KeyT, _ValueT, _HashT, _PredT, std::pmr::polymorphic_allocator>>; -_LIBCPP_END_NAMESPACE_STD_PMR + +} // namespace pmr + +} // namespace std + #endif #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 diff --git a/libcxx/include/unordered_set b/libcxx/include/unordered_set index dd9bd09ddbf67..eb67eb5d957af 100644 --- a/libcxx/include/unordered_set +++ b/libcxx/include/unordered_set @@ -1804,13 +1804,21 @@ operator!=(const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x, _LIBCPP_END_NAMESPACE_STD #if _LIBCPP_STD_VER > 14 -_LIBCPP_BEGIN_NAMESPACE_STD_PMR + +namespace std { + +namespace pmr { + template , class _PredT = std::equal_to<_KeyT>> using unordered_set = std::unordered_set<_KeyT, _HashT, _PredT, std::pmr::polymorphic_allocator<_KeyT>>; template , class _PredT = std::equal_to<_KeyT>> using unordered_multiset = std::unordered_multiset<_KeyT, _HashT, _PredT, std::pmr::polymorphic_allocator<_KeyT>>; -_LIBCPP_END_NAMESPACE_STD_PMR + +} // namespace pmr + +} // namespace std + #endif #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 diff --git a/libcxx/include/vector b/libcxx/include/vector index d1277b94e0f64..89d5ae8109cf1 100644 --- a/libcxx/include/vector +++ b/libcxx/include/vector @@ -3272,12 +3272,18 @@ inline constexpr bool __format::__enable_insertable> = true _LIBCPP_END_NAMESPACE_STD #if _LIBCPP_STD_VER > 14 -_LIBCPP_BEGIN_NAMESPACE_STD_PMR + +namespace std { + namespace pmr { + template using vector = std::vector<_ValueT, std::pmr::polymorphic_allocator<_ValueT>>; + } // namespace pmr -_LIBCPP_END_NAMESPACE_STD_PMR + +} // namespace std + #endif _LIBCPP_POP_MACROS diff --git a/libcxx/src/support/runtime/memory_resource_msvc.ipp b/libcxx/src/support/runtime/memory_resource_msvc.ipp index 96b25434deef4..9f28f58a4e7b7 100644 --- a/libcxx/src/support/runtime/memory_resource_msvc.ipp +++ b/libcxx/src/support/runtime/memory_resource_msvc.ipp @@ -30,7 +30,6 @@ namespace std { namespace pmr { memory_resource* get_default_resource() noexcept { - printf("Debug: compat get_default_resouce\n"); #ifdef __cpp_aligned_new return ::_Aligned_get_default_resource(); #else @@ -39,7 +38,6 @@ memory_resource* get_default_resource() noexcept { } memory_resource* set_default_resource(memory_resource* __new_res) noexcept { - printf("Debug: compat set_default_resouce\n"); #ifdef __cpp_aligned_new return ::_Aligned_set_default_resource(__new_res); #else From f5cbd1ed371f5be62b4ea3b45e59dad2a747799b Mon Sep 17 00:00:00 2001 From: kboyarinov Date: Thu, 22 Dec 2022 10:54:29 -0600 Subject: [PATCH 23/26] More cosmetic changes --- libcxx/include/__fwd/string.h | 1 - libcxx/include/deque | 2 -- libcxx/include/forward_list | 4 +--- libcxx/include/list | 4 +--- libcxx/include/map | 6 ++---- libcxx/include/regex | 4 +--- libcxx/include/set | 6 ++---- libcxx/include/unordered_map | 6 ++---- libcxx/include/unordered_set | 6 ++---- libcxx/include/vector | 4 +--- 10 files changed, 12 insertions(+), 31 deletions(-) diff --git a/libcxx/include/__fwd/string.h b/libcxx/include/__fwd/string.h index ea7cb25c56a9d..0e4be581d5de3 100644 --- a/libcxx/include/__fwd/string.h +++ b/libcxx/include/__fwd/string.h @@ -106,7 +106,6 @@ using u16string = basic_string; using u32string = basic_string; } // namespace pmr - } // namespace std #endif // _LIBCPP_STD_VER >= 17 diff --git a/libcxx/include/deque b/libcxx/include/deque index e3baf114e3a32..a2447a21e0623 100644 --- a/libcxx/include/deque +++ b/libcxx/include/deque @@ -2935,10 +2935,8 @@ _LIBCPP_END_NAMESPACE_STD namespace std { namespace pmr { - template using deque = std::deque<_ValueT, polymorphic_allocator<_ValueT>>; - } // namespace pmr } // namespace std diff --git a/libcxx/include/forward_list b/libcxx/include/forward_list index ac441b422df1a..4873ad5e004d9 100644 --- a/libcxx/include/forward_list +++ b/libcxx/include/forward_list @@ -1784,10 +1784,8 @@ _LIBCPP_END_NAMESPACE_STD namespace std { namespace pmr { - template -using forward_list = std::forward_list<_ValueT, std::pmr::polymorphic_allocator<_ValueT>>; - +using forward_list = std::forward_list<_ValueT, polymorphic_allocator<_ValueT>>; } // namespace pmr } // namespace std diff --git a/libcxx/include/list b/libcxx/include/list index 027b1cbb1c0dc..c79a617595913 100644 --- a/libcxx/include/list +++ b/libcxx/include/list @@ -2367,10 +2367,8 @@ _LIBCPP_END_NAMESPACE_STD namespace std { namespace pmr { - template -using list = std::list<_ValueT, std::pmr::polymorphic_allocator<_ValueT>>; - +using list = std::list<_ValueT, polymorphic_allocator<_ValueT>>; } // namespace pmr } // namespace std diff --git a/libcxx/include/map b/libcxx/include/map index df3da627680ef..34956149c60c1 100644 --- a/libcxx/include/map +++ b/libcxx/include/map @@ -2344,13 +2344,11 @@ _LIBCPP_END_NAMESPACE_STD namespace std { namespace pmr { - template > -using map = std::map<_KeyT, _ValueT, _CompareT, std::pmr::polymorphic_allocator>>; +using map = std::map<_KeyT, _ValueT, _CompareT, polymorphic_allocator>>; template > -using multimap = std::multimap<_KeyT, _ValueT, _CompareT, std::pmr::polymorphic_allocator>>; - +using multimap = std::multimap<_KeyT, _ValueT, _CompareT, polymorphic_allocator>>; } // namespace pmr } // namespace std diff --git a/libcxx/include/regex b/libcxx/include/regex index 8527cee3388d7..7bdb42f7e80cf 100644 --- a/libcxx/include/regex +++ b/libcxx/include/regex @@ -6849,9 +6849,8 @@ _LIBCPP_END_NAMESPACE_STD namespace std { namespace pmr { - template -using match_results = std::match_results<_BidirT, std::pmr::polymorphic_allocator>>; +using match_results = std::match_results<_BidirT, polymorphic_allocator>>; using cmatch = match_results; using smatch = match_results; @@ -6860,7 +6859,6 @@ using smatch = match_results; using wcmatch = match_results; using wsmatch = match_results; #endif - } // namespace pmr } // namespace std diff --git a/libcxx/include/set b/libcxx/include/set index da8c8d1ce3d99..24ede7521725e 100644 --- a/libcxx/include/set +++ b/libcxx/include/set @@ -1589,13 +1589,11 @@ _LIBCPP_END_NAMESPACE_STD namespace std { namespace pmr { - template > -using set = std::set<_KeyT, _CompareT, std::pmr::polymorphic_allocator<_KeyT>>; +using set = std::set<_KeyT, _CompareT, polymorphic_allocator<_KeyT>>; template > -using multiset = std::multiset<_KeyT, _CompareT, std::pmr::polymorphic_allocator<_KeyT>>; - +using multiset = std::multiset<_KeyT, _CompareT, polymorphic_allocator<_KeyT>>; } // namespace pmr } // namespace std diff --git a/libcxx/include/unordered_map b/libcxx/include/unordered_map index 7b176a1e5ed65..28ee33afbfbd6 100644 --- a/libcxx/include/unordered_map +++ b/libcxx/include/unordered_map @@ -2634,15 +2634,13 @@ _LIBCPP_END_NAMESPACE_STD namespace std { namespace pmr { - template , class _PredT = std::equal_to<_KeyT>> using unordered_map = - std::unordered_map<_KeyT, _ValueT, _HashT, _PredT, std::pmr::polymorphic_allocator>>; + std::unordered_map<_KeyT, _ValueT, _HashT, _PredT, polymorphic_allocator>>; template , class _PredT = std::equal_to<_KeyT>> using unordered_multimap = - std::unordered_multimap<_KeyT, _ValueT, _HashT, _PredT, std::pmr::polymorphic_allocator>>; - + std::unordered_multimap<_KeyT, _ValueT, _HashT, _PredT, polymorphic_allocator>>; } // namespace pmr } // namespace std diff --git a/libcxx/include/unordered_set b/libcxx/include/unordered_set index eb67eb5d957af..84068b54c4432 100644 --- a/libcxx/include/unordered_set +++ b/libcxx/include/unordered_set @@ -1808,13 +1808,11 @@ _LIBCPP_END_NAMESPACE_STD namespace std { namespace pmr { - template , class _PredT = std::equal_to<_KeyT>> -using unordered_set = std::unordered_set<_KeyT, _HashT, _PredT, std::pmr::polymorphic_allocator<_KeyT>>; +using unordered_set = std::unordered_set<_KeyT, _HashT, _PredT, polymorphic_allocator<_KeyT>>; template , class _PredT = std::equal_to<_KeyT>> -using unordered_multiset = std::unordered_multiset<_KeyT, _HashT, _PredT, std::pmr::polymorphic_allocator<_KeyT>>; - +using unordered_multiset = std::unordered_multiset<_KeyT, _HashT, _PredT, polymorphic_allocator<_KeyT>>; } // namespace pmr } // namespace std diff --git a/libcxx/include/vector b/libcxx/include/vector index 89d5ae8109cf1..468f37ec4c2e9 100644 --- a/libcxx/include/vector +++ b/libcxx/include/vector @@ -3276,10 +3276,8 @@ _LIBCPP_END_NAMESPACE_STD namespace std { namespace pmr { - template -using vector = std::vector<_ValueT, std::pmr::polymorphic_allocator<_ValueT>>; - +using vector = std::vector<_ValueT, polymorphic_allocator<_ValueT>>; } // namespace pmr } // namespace std From 8a9e08234539cc9997157dd06666f9df750b0148 Mon Sep 17 00:00:00 2001 From: kboyarinov Date: Mon, 26 Dec 2022 14:06:44 +0200 Subject: [PATCH 24/26] Fix string and fallback compilation --- libcxx/include/__fwd/string.h | 54 ++++++------ .../runtime/memory_resource_fallback.ipp | 88 +++++++++---------- 2 files changed, 73 insertions(+), 69 deletions(-) diff --git a/libcxx/include/__fwd/string.h b/libcxx/include/__fwd/string.h index 0e4be581d5de3..24e3bf3e524de 100644 --- a/libcxx/include/__fwd/string.h +++ b/libcxx/include/__fwd/string.h @@ -57,35 +57,10 @@ using u8string = basic_string; using u16string = basic_string; using u32string = basic_string; -// clang-format off -template -class _LIBCPP_PREFERRED_NAME(string) -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS - _LIBCPP_PREFERRED_NAME(wstring) -#endif -#ifndef _LIBCPP_HAS_NO_CHAR8_T - _LIBCPP_PREFERRED_NAME(u8string) -#endif - _LIBCPP_PREFERRED_NAME(u16string) - _LIBCPP_PREFERRED_NAME(u32string) #if _LIBCPP_STD_VER >= 17 - _LIBCPP_PREFERRED_NAME(pmr::string) -# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS - _LIBCPP_PREFERRED_NAME(pmr::wstring) -# endif -# ifndef _LIBCPP_HAS_NO_CHAR8_T - _LIBCPP_PREFERRED_NAME(pmr::u8string) -# endif - _LIBCPP_PREFERRED_NAME(pmr::u16string) - _LIBCPP_PREFERRED_NAME(pmr::u32string) -#endif - basic_string; -// clang-format on _LIBCPP_END_NAMESPACE_STD -#if _LIBCPP_STD_VER >= 17 - namespace std { namespace pmr { @@ -108,6 +83,35 @@ using u32string = basic_string; } // namespace pmr } // namespace std +_LIBCPP_BEGIN_NAMESPACE_STD + #endif // _LIBCPP_STD_VER >= 17 +// clang-format off +template +class _LIBCPP_PREFERRED_NAME(string) +#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS + _LIBCPP_PREFERRED_NAME(wstring) +#endif +#ifndef _LIBCPP_HAS_NO_CHAR8_T + _LIBCPP_PREFERRED_NAME(u8string) +#endif + _LIBCPP_PREFERRED_NAME(u16string) + _LIBCPP_PREFERRED_NAME(u32string) +#if _LIBCPP_STD_VER >= 17 + _LIBCPP_PREFERRED_NAME(pmr::string) +# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS + _LIBCPP_PREFERRED_NAME(pmr::wstring) +# endif +# ifndef _LIBCPP_HAS_NO_CHAR8_T + _LIBCPP_PREFERRED_NAME(pmr::u8string) +# endif + _LIBCPP_PREFERRED_NAME(pmr::u16string) + _LIBCPP_PREFERRED_NAME(pmr::u32string) +#endif + basic_string; +// clang-format on + +_LIBCPP_END_NAMESPACE_STD + #endif // _LIBCPP___FWD_STRING_H diff --git a/libcxx/src/support/runtime/memory_resource_fallback.ipp b/libcxx/src/support/runtime/memory_resource_fallback.ipp index 9685c498b20c7..b31cb886ebc2c 100644 --- a/libcxx/src/support/runtime/memory_resource_fallback.ipp +++ b/libcxx/src/support/runtime/memory_resource_fallback.ipp @@ -11,50 +11,6 @@ namespace std { namespace pmr { -// default_memory_resource() - -static memory_resource* __default_memory_resource(bool set = false, memory_resource* new_res = nullptr) noexcept { -#ifndef _LIBCPP_HAS_NO_ATOMIC_HEADER - static constinit atomic __res{&res_init.resources.new_delete_res}; - if (set) { - new_res = new_res ? new_res : new_delete_resource(); - // TODO: Can a weaker ordering be used? - return std::atomic_exchange_explicit(&__res, new_res, memory_order_acq_rel); - } else { - return std::atomic_load_explicit(&__res, memory_order_acquire); - } -#elif !defined(_LIBCPP_HAS_NO_THREADS) - static constinit memory_resource* res = &res_init.resources.new_delete_res; - static mutex res_lock; - if (set) { - new_res = new_res ? new_res : new_delete_resource(); - lock_guard guard(res_lock); - memory_resource* old_res = res; - res = new_res; - return old_res; - } else { - lock_guard guard(res_lock); - return res; - } -#else - static constinit memory_resource* res = &res_init.resources.new_delete_res; - if (set) { - new_res = new_res ? new_res : new_delete_resource(); - memory_resource* old_res = res; - res = new_res; - return old_res; - } else { - return res; - } -#endif -} - -memory_resource* get_default_resource() noexcept { return __default_memory_resource(); } - -memory_resource* set_default_resource(memory_resource* __new_res) noexcept { - return __default_memory_resource(true, __new_res); -} - // new_delete_resource() #ifdef _LIBCPP_HAS_NO_ALIGNED_ALLOCATION @@ -117,5 +73,49 @@ memory_resource* new_delete_resource() noexcept { return &res_init.resources.new memory_resource* null_memory_resource() noexcept { return &res_init.resources.null_res; } +// default_memory_resource() + +static memory_resource* __default_memory_resource(bool set = false, memory_resource* new_res = nullptr) noexcept { +#ifndef _LIBCPP_HAS_NO_ATOMIC_HEADER + static constinit atomic __res{&res_init.resources.new_delete_res}; + if (set) { + new_res = new_res ? new_res : new_delete_resource(); + // TODO: Can a weaker ordering be used? + return std::atomic_exchange_explicit(&__res, new_res, memory_order_acq_rel); + } else { + return std::atomic_load_explicit(&__res, memory_order_acquire); + } +#elif !defined(_LIBCPP_HAS_NO_THREADS) + static constinit memory_resource* res = &res_init.resources.new_delete_res; + static mutex res_lock; + if (set) { + new_res = new_res ? new_res : new_delete_resource(); + lock_guard guard(res_lock); + memory_resource* old_res = res; + res = new_res; + return old_res; + } else { + lock_guard guard(res_lock); + return res; + } +#else + static constinit memory_resource* res = &res_init.resources.new_delete_res; + if (set) { + new_res = new_res ? new_res : new_delete_resource(); + memory_resource* old_res = res; + res = new_res; + return old_res; + } else { + return res; + } +#endif +} + +memory_resource* get_default_resource() noexcept { return __default_memory_resource(); } + +memory_resource* set_default_resource(memory_resource* __new_res) noexcept { + return __default_memory_resource(true, __new_res); +} + } // namespace pmr } // namespace std From 5064635c8e095771a11752ee70ec035eb807a23f Mon Sep 17 00:00:00 2001 From: kboyarinov Date: Mon, 9 Jan 2023 13:22:17 +0200 Subject: [PATCH 25/26] Remove unnecessary whitespace changes in vector --- libcxx/include/vector | 46 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/libcxx/include/vector b/libcxx/include/vector index 468f37ec4c2e9..092a8969a3c7d 100644 --- a/libcxx/include/vector +++ b/libcxx/include/vector @@ -12,8 +12,10 @@ /* vector synopsis + namespace std { + template > class vector { @@ -30,6 +32,7 @@ public: typedef typename allocator_type::const_pointer const_pointer; typedef std::reverse_iterator reverse_iterator; typedef std::reverse_iterator const_reverse_iterator; + vector() noexcept(is_nothrow_default_constructible::value); explicit vector(const allocator_type&); @@ -54,40 +57,50 @@ public: void assign(InputIterator first, InputIterator last); void assign(size_type n, const value_type& u); void assign(initializer_list il); + allocator_type get_allocator() const noexcept; + iterator begin() noexcept; const_iterator begin() const noexcept; iterator end() noexcept; const_iterator end() const noexcept; + reverse_iterator rbegin() noexcept; const_reverse_iterator rbegin() const noexcept; reverse_iterator rend() noexcept; const_reverse_iterator rend() const noexcept; + const_iterator cbegin() const noexcept; const_iterator cend() const noexcept; const_reverse_iterator crbegin() const noexcept; const_reverse_iterator crend() const noexcept; + size_type size() const noexcept; size_type max_size() const noexcept; size_type capacity() const noexcept; bool empty() const noexcept; void reserve(size_type n); void shrink_to_fit() noexcept; + reference operator[](size_type n); const_reference operator[](size_type n) const; reference at(size_type n); const_reference at(size_type n) const; + reference front(); const_reference front() const; reference back(); const_reference back() const; + value_type* data() noexcept; const value_type* data() const noexcept; + void push_back(const value_type& x); void push_back(value_type&& x); template reference emplace_back(Args&&... args); // reference in C++17 void pop_back(); + template iterator emplace(const_iterator position, Args&&... args); iterator insert(const_iterator position, const value_type& x); iterator insert(const_iterator position, value_type&& x); @@ -95,16 +108,22 @@ public: template iterator insert(const_iterator position, InputIterator first, InputIterator last); iterator insert(const_iterator position, initializer_list il); + iterator erase(const_iterator position); iterator erase(const_iterator first, const_iterator last); + void clear() noexcept; + void resize(size_type sz); void resize(size_type sz, const value_type& c); + void swap(vector&) noexcept(allocator_traits::propagate_on_container_swap::value || allocator_traits::is_always_equal::value); // C++17 + bool __invariants() const; }; + template > class vector { @@ -119,6 +138,7 @@ public: typedef const_iterator const_pointer; typedef std::reverse_iterator reverse_iterator; typedef std::reverse_iterator const_reverse_iterator; + class reference { public: @@ -129,6 +149,7 @@ public: iterator operator&() const noexcept; void flip() noexcept; }; + class const_reference { public: @@ -136,6 +157,7 @@ public: operator bool() const noexcept; const_iterator operator&() const noexcept; }; + vector() noexcept(is_nothrow_default_constructible::value); explicit vector(const allocator_type&); @@ -159,73 +181,94 @@ public: void assign(InputIterator first, InputIterator last); void assign(size_type n, const value_type& u); void assign(initializer_list il); + allocator_type get_allocator() const noexcept; + iterator begin() noexcept; const_iterator begin() const noexcept; iterator end() noexcept; const_iterator end() const noexcept; + reverse_iterator rbegin() noexcept; const_reverse_iterator rbegin() const noexcept; reverse_iterator rend() noexcept; const_reverse_iterator rend() const noexcept; + const_iterator cbegin() const noexcept; const_iterator cend() const noexcept; const_reverse_iterator crbegin() const noexcept; const_reverse_iterator crend() const noexcept; + size_type size() const noexcept; size_type max_size() const noexcept; size_type capacity() const noexcept; bool empty() const noexcept; void reserve(size_type n); void shrink_to_fit() noexcept; + reference operator[](size_type n); const_reference operator[](size_type n) const; reference at(size_type n); const_reference at(size_type n) const; + reference front(); const_reference front() const; reference back(); const_reference back() const; + void push_back(const value_type& x); template reference emplace_back(Args&&... args); // C++14; reference in C++17 void pop_back(); + template iterator emplace(const_iterator position, Args&&... args); // C++14 iterator insert(const_iterator position, const value_type& x); iterator insert(const_iterator position, size_type n, const value_type& x); template iterator insert(const_iterator position, InputIterator first, InputIterator last); iterator insert(const_iterator position, initializer_list il); + iterator erase(const_iterator position); iterator erase(const_iterator first, const_iterator last); + void clear() noexcept; + void resize(size_type sz); void resize(size_type sz, value_type x); + void swap(vector&) noexcept(allocator_traits::propagate_on_container_swap::value || allocator_traits::is_always_equal::value); // C++17 void flip() noexcept; + bool __invariants() const; }; + template ::value_type>> vector(InputIterator, InputIterator, Allocator = Allocator()) -> vector::value_type, Allocator>; // C++17 + template struct hash>; + template bool operator==(const vector& x, const vector& y); template bool operator< (const vector& x, const vector& y); template bool operator!=(const vector& x, const vector& y); template bool operator> (const vector& x, const vector& y); template bool operator>=(const vector& x, const vector& y); template bool operator<=(const vector& x, const vector& y); + template void swap(vector& x, vector& y) noexcept(noexcept(x.swap(y))); + template typename vector::size_type erase(vector& c, const U& value); // C++20 template typename vector::size_type erase_if(vector& c, Predicate pred); // C++20 + } // std + */ #include <__algorithm/copy.h> @@ -3272,7 +3315,6 @@ inline constexpr bool __format::__enable_insertable> = true _LIBCPP_END_NAMESPACE_STD #if _LIBCPP_STD_VER > 14 - namespace std { namespace pmr { @@ -3281,7 +3323,7 @@ using vector = std::vector<_ValueT, polymorphic_allocator<_ValueT>>; } // namespace pmr } // namespace std - +_LIBCPP_END_NAMESPACE_STD #endif _LIBCPP_POP_MACROS From 3208eb7efea488b8993175e522bbe2152b1cdae0 Mon Sep 17 00:00:00 2001 From: kboyarinov Date: Mon, 9 Jan 2023 13:23:32 +0200 Subject: [PATCH 26/26] Add newline for vector --- libcxx/include/vector | 1 + 1 file changed, 1 insertion(+) diff --git a/libcxx/include/vector b/libcxx/include/vector index 092a8969a3c7d..d67c04c76644c 100644 --- a/libcxx/include/vector +++ b/libcxx/include/vector @@ -3323,6 +3323,7 @@ using vector = std::vector<_ValueT, polymorphic_allocator<_ValueT>>; } // namespace pmr } // namespace std + _LIBCPP_END_NAMESPACE_STD #endif