Skip to content

Commit f11abac

Browse files
authored
Revert "[libc++][modules] Rewrite the modulemap to have fewer top-level modules (#107638)" (#110384)
This reverts 3 commits: 45a09d1 24bc324 bc6bd3b The GitHub pre-merge CI has been broken since this PR went in. This change reverts it to see if I can get the pre-merge CI working again.
1 parent bf9ab0b commit f11abac

File tree

21 files changed

+2414
-2835
lines changed

21 files changed

+2414
-2835
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
set(LIBCXX_HARDENING_MODE "fast" CACHE STRING "")
2-
set(LIBCXX_ABI_DEFINES "_LIBCPP_ABI_BOUNDED_ITERATORS;_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STRING;_LIBCPP_ABI_BOUNDED_ITERATORS_IN_VECTOR;_LIBCPP_ABI_BOUNDED_UNIQUE_PTR" CACHE STRING "")
2+
set(LIBCXX_ABI_DEFINES "_LIBCPP_ABI_BOUNDED_ITERATORS;_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STRING;_LIBCPP_ABI_BOUNDED_ITERATORS_IN_VECTOR" CACHE STRING "")

libcxx/include/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ set(files
2323
__algorithm/find_if.h
2424
__algorithm/find_if_not.h
2525
__algorithm/find_segment_if.h
26+
__algorithm/fold.h
2627
__algorithm/for_each.h
2728
__algorithm/for_each_n.h
2829
__algorithm/for_each_segment.h
@@ -97,7 +98,6 @@ set(files
9798
__algorithm/ranges_find_if.h
9899
__algorithm/ranges_find_if_not.h
99100
__algorithm/ranges_find_last.h
100-
__algorithm/ranges_fold.h
101101
__algorithm/ranges_for_each.h
102102
__algorithm/ranges_for_each_n.h
103103
__algorithm/ranges_generate.h
@@ -536,7 +536,6 @@ set(files
536536
__memory/allocator_arg_t.h
537537
__memory/allocator_destructor.h
538538
__memory/allocator_traits.h
539-
__memory/array_cookie.h
540539
__memory/assume_aligned.h
541540
__memory/auto_ptr.h
542541
__memory/builtin_new_allocator.h
@@ -688,6 +687,7 @@ set(files
688687
__ranges/views.h
689688
__ranges/zip_view.h
690689
__split_buffer
690+
__std_clang_module
691691
__std_mbstate_t.h
692692
__stop_token/atomic_unique_lock.h
693693
__stop_token/intrusive_list_view.h

libcxx/include/__algorithm/ranges_fold.h renamed to libcxx/include/__algorithm/fold.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
//
88
//===----------------------------------------------------------------------===//
99

10-
#ifndef _LIBCPP___ALGORITHM_RANGES_FOLD_H
11-
#define _LIBCPP___ALGORITHM_RANGES_FOLD_H
10+
#ifndef _LIBCPP___ALGORITHM_FOLD_H
11+
#define _LIBCPP___ALGORITHM_FOLD_H
1212

1313
#include <__concepts/assignable.h>
1414
#include <__concepts/constructible.h>
@@ -126,4 +126,4 @@ _LIBCPP_END_NAMESPACE_STD
126126

127127
_LIBCPP_POP_MACROS
128128

129-
#endif // _LIBCPP___ALGORITHM_RANGES_FOLD_H
129+
#endif // _LIBCPP___ALGORITHM_FOLD_H

libcxx/include/__configuration/abi.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,6 @@
181181
# define _LIBCPP_ABI_NO_COMPRESSED_PAIR_PADDING
182182
#endif
183183

184-
// Tracks the bounds of the array owned by std::unique_ptr<T[]>, allowing it to trap when accessed out-of-bounds.
185-
// Note that limited bounds checking is also available outside of this ABI configuration, but only some categories
186-
// of types can be checked.
187-
//
188-
// ABI impact: This causes the layout of std::unique_ptr<T[]> to change and its size to increase.
189-
// #define _LIBCPP_ABI_BOUNDED_UNIQUE_PTR
190-
191184
#if defined(_LIBCPP_COMPILER_CLANG_BASED)
192185
# if defined(__APPLE__)
193186
# if defined(__i386__) || defined(__x86_64__)

libcxx/include/__format/formatter_integral.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include <__type_traits/make_unsigned.h>
2828
#include <__utility/unreachable.h>
2929
#include <array>
30-
#include <cstdint>
3130
#include <limits>
3231
#include <string>
3332
#include <string_view>

libcxx/include/__memory/array_cookie.h

Lines changed: 0 additions & 55 deletions
This file was deleted.

libcxx/include/__memory/unique_ptr.h

Lines changed: 5 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,15 @@
1010
#ifndef _LIBCPP___MEMORY_UNIQUE_PTR_H
1111
#define _LIBCPP___MEMORY_UNIQUE_PTR_H
1212

13-
#include <__assert>
1413
#include <__compare/compare_three_way.h>
1514
#include <__compare/compare_three_way_result.h>
1615
#include <__compare/three_way_comparable.h>
1716
#include <__config>
1817
#include <__functional/hash.h>
1918
#include <__functional/operations.h>
2019
#include <__memory/allocator_traits.h> // __pointer
21-
#include <__memory/array_cookie.h>
2220
#include <__memory/auto_ptr.h>
2321
#include <__memory/compressed_pair.h>
24-
#include <__memory/pointer_traits.h>
2522
#include <__type_traits/add_lvalue_reference.h>
2623
#include <__type_traits/common_type.h>
2724
#include <__type_traits/conditional.h>
@@ -30,7 +27,6 @@
3027
#include <__type_traits/integral_constant.h>
3128
#include <__type_traits/is_array.h>
3229
#include <__type_traits/is_assignable.h>
33-
#include <__type_traits/is_constant_evaluated.h>
3430
#include <__type_traits/is_constructible.h>
3531
#include <__type_traits/is_convertible.h>
3632
#include <__type_traits/is_function.h>
@@ -45,9 +41,7 @@
4541
#include <__utility/declval.h>
4642
#include <__utility/forward.h>
4743
#include <__utility/move.h>
48-
#include <__utility/private_constructor_tag.h>
4944
#include <cstddef>
50-
#include <cstdint>
5145

5246
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
5347
# pragma GCC system_header
@@ -298,91 +292,6 @@ class _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS unique_ptr {
298292
}
299293
};
300294

301-
// Bounds checking in unique_ptr<T[]>
302-
// ==================================
303-
//
304-
// We provide some helper classes that allow bounds checking when accessing a unique_ptr<T[]>.
305-
// There are a few cases where bounds checking can be implemented:
306-
//
307-
// 1. When an array cookie (see [1]) exists at the beginning of the array allocation, we are
308-
// able to reuse that cookie to extract the size of the array and perform bounds checking.
309-
// An array cookie is a size inserted at the beginning of the allocation by the compiler.
310-
// That size is inserted implicitly when doing `new T[n]` in some cases, and its purpose
311-
// is to allow the runtime to destroy the `n` array elements when doing `delete array`.
312-
// When we are able to use array cookies, we reuse information already available in the
313-
// current runtime, so bounds checking does not require changing libc++'s ABI.
314-
//
315-
// 2. When the "bounded unique_ptr" ABI configuration (controlled by `_LIBCPP_ABI_BOUNDED_UNIQUE_PTR`)
316-
// is enabled, we store the size of the allocation (when it is known) so we can check it when
317-
// indexing into the `unique_ptr`. That changes the layout of `std::unique_ptr<T[]>`, which is
318-
// an ABI break from the default configuration.
319-
//
320-
// Note that even under this ABI configuration, we can't always know the size of the unique_ptr.
321-
// Indeed, the size of the allocation can only be known when the unique_ptr is created via
322-
// make_unique or a similar API. For example, it can't be known when constructed from an arbitrary
323-
// pointer, in which case we are not able to check the bounds on access:
324-
//
325-
// unique_ptr<T[], MyDeleter> ptr(new T[3]);
326-
//
327-
// When we don't know the size of the allocation via the API used to create the unique_ptr, we
328-
// try to fall back to using an array cookie when available.
329-
//
330-
// Finally, note that when this ABI configuration is enabled, we have no choice but to always
331-
// make space for a size to be stored in the unique_ptr. Indeed, while we might want to avoid
332-
// storing the size when an array cookie is available, knowing whether an array cookie is available
333-
// requires the type stored in the unique_ptr to be complete, while unique_ptr can normally
334-
// accommodate incomplete types.
335-
//
336-
// (1) Implementation where we rely on the array cookie to know the size of the allocation, if
337-
// an array cookie exists.
338-
struct __unique_ptr_array_bounds_stateless {
339-
__unique_ptr_array_bounds_stateless() = default;
340-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __unique_ptr_array_bounds_stateless(size_t) {}
341-
342-
template <class _Tp, __enable_if_t<__has_array_cookie<_Tp>::value, int> = 0>
343-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool __in_bounds(_Tp* __ptr, size_t __index) const {
344-
// In constant expressions, we can't check the array cookie so we just pretend that the index
345-
// is in-bounds. The compiler catches invalid accesses anyway.
346-
if (__libcpp_is_constant_evaluated())
347-
return true;
348-
size_t __cookie = std::__get_array_cookie(__ptr);
349-
return __index < __cookie;
350-
}
351-
352-
template <class _Tp, __enable_if_t<!__has_array_cookie<_Tp>::value, int> = 0>
353-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool __in_bounds(_Tp*, size_t) const {
354-
return true; // If we don't have an array cookie, we assume the access is in-bounds
355-
}
356-
};
357-
358-
// (2) Implementation where we store the size in the class whenever we have it.
359-
//
360-
// Semantically, we'd need to store the size as an optional<size_t>. However, since that
361-
// is really heavy weight, we instead store a size_t and use SIZE_MAX as a magic value
362-
// meaning that we don't know the size.
363-
struct __unique_ptr_array_bounds_stored {
364-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __unique_ptr_array_bounds_stored() : __size_(SIZE_MAX) {}
365-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __unique_ptr_array_bounds_stored(size_t __size) : __size_(__size) {}
366-
367-
// Use the array cookie if there's one
368-
template <class _Tp, __enable_if_t<__has_array_cookie<_Tp>::value, int> = 0>
369-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool __in_bounds(_Tp* __ptr, size_t __index) const {
370-
if (__libcpp_is_constant_evaluated())
371-
return true;
372-
size_t __cookie = std::__get_array_cookie(__ptr);
373-
return __index < __cookie;
374-
}
375-
376-
// Otherwise, fall back on the stored size (if any)
377-
template <class _Tp, __enable_if_t<!__has_array_cookie<_Tp>::value, int> = 0>
378-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool __in_bounds(_Tp*, size_t __index) const {
379-
return __index < __size_;
380-
}
381-
382-
private:
383-
size_t __size_;
384-
};
385-
386295
template <class _Tp, class _Dp>
387296
class _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS unique_ptr<_Tp[], _Dp> {
388297
public:
@@ -391,9 +300,8 @@ class _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS unique_ptr<_Tp[], _Dp>
391300
typedef typename __pointer<_Tp, deleter_type>::type pointer;
392301

393302
// A unique_ptr contains the following members which may be trivially relocatable:
394-
// - pointer: this may be trivially relocatable, so it's checked
303+
// - pointer : this may be trivially relocatable, so it's checked
395304
// - deleter_type: this may be trivially relocatable, so it's checked
396-
// - (optionally) size: this is trivially relocatable
397305
//
398306
// This unique_ptr implementation only contains a pointer to the unique object and a deleter, so there are no
399307
// references to itself. This means that the entire structure is trivially relocatable if its members are.
@@ -403,16 +311,7 @@ class _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS unique_ptr<_Tp[], _Dp>
403311
void>;
404312

405313
private:
406-
template <class _Up, class _OtherDeleter>
407-
friend class unique_ptr;
408-
409314
_LIBCPP_COMPRESSED_PAIR(pointer, __ptr_, deleter_type, __deleter_);
410-
#ifdef _LIBCPP_ABI_BOUNDED_UNIQUE_PTR
411-
using _BoundsChecker = __unique_ptr_array_bounds_stored;
412-
#else
413-
using _BoundsChecker = __unique_ptr_array_bounds_stateless;
414-
#endif
415-
_LIBCPP_NO_UNIQUE_ADDRESS _BoundsChecker __checker_;
416315

417316
template <class _From>
418317
struct _CheckArrayPointerConversion : is_same<_From, pointer> {};
@@ -474,12 +373,6 @@ class _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS unique_ptr<_Tp[], _Dp>
474373
: __ptr_(__p),
475374
__deleter_() {}
476375

477-
// Private constructor used by make_unique & friends to pass the size that was allocated
478-
template <class _Tag, class _Ptr, __enable_if_t<is_same<_Tag, __private_constructor_tag>::value, int> = 0>
479-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 explicit unique_ptr(_Tag, _Ptr __ptr, size_t __size) _NOEXCEPT
480-
: __ptr_(__ptr),
481-
__checker_(__size) {}
482-
483376
template <class _Pp,
484377
bool _Dummy = true,
485378
class = _EnableIfDeleterConstructible<_LValRefType<_Dummy> >,
@@ -518,13 +411,11 @@ class _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS unique_ptr<_Tp[], _Dp>
518411

519412
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(unique_ptr&& __u) _NOEXCEPT
520413
: __ptr_(__u.release()),
521-
__deleter_(std::forward<deleter_type>(__u.get_deleter())),
522-
__checker_(std::move(__u.__checker_)) {}
414+
__deleter_(std::forward<deleter_type>(__u.get_deleter())) {}
523415

524416
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT {
525417
reset(__u.release());
526418
__deleter_ = std::forward<deleter_type>(__u.get_deleter());
527-
__checker_ = std::move(std::move(__u.__checker_));
528419
return *this;
529420
}
530421

@@ -534,8 +425,7 @@ class _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS unique_ptr<_Tp[], _Dp>
534425
class = _EnableIfDeleterConvertible<_Ep> >
535426
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
536427
: __ptr_(__u.release()),
537-
__deleter_(std::forward<_Ep>(__u.get_deleter())),
538-
__checker_(std::move(__u.__checker_)) {}
428+
__deleter_(std::forward<_Ep>(__u.get_deleter())) {}
539429

540430
template <class _Up,
541431
class _Ep,
@@ -544,7 +434,6 @@ class _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS unique_ptr<_Tp[], _Dp>
544434
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr& operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT {
545435
reset(__u.release());
546436
__deleter_ = std::forward<_Ep>(__u.get_deleter());
547-
__checker_ = std::move(__u.__checker_);
548437
return *this;
549438
}
550439

@@ -562,8 +451,6 @@ class _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS unique_ptr<_Tp[], _Dp>
562451
}
563452

564453
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 __add_lvalue_reference_t<_Tp> operator[](size_t __i) const {
565-
_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__checker_.__in_bounds(std::__to_address(__ptr_), __i),
566-
"unique_ptr<T[]>::operator[](index): index out of range");
567454
return __ptr_[__i];
568455
}
569456
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 pointer get() const _NOEXCEPT { return __ptr_; }
@@ -580,24 +467,20 @@ class _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS unique_ptr<_Tp[], _Dp>
580467
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 pointer release() _NOEXCEPT {
581468
pointer __t = __ptr_;
582469
__ptr_ = pointer();
583-
// The deleter and the optional bounds-checker are left unchanged. The bounds-checker
584-
// will be reinitialized appropriately when/if the unique_ptr gets assigned-to or reset.
585470
return __t;
586471
}
587472

588473
template <class _Pp, __enable_if_t<_CheckArrayPointerConversion<_Pp>::value, int> = 0>
589474
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void reset(_Pp __p) _NOEXCEPT {
590475
pointer __tmp = __ptr_;
591476
__ptr_ = __p;
592-
__checker_ = _BoundsChecker();
593477
if (__tmp)
594478
__deleter_(__tmp);
595479
}
596480

597481
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void reset(nullptr_t = nullptr) _NOEXCEPT {
598482
pointer __tmp = __ptr_;
599483
__ptr_ = nullptr;
600-
__checker_ = _BoundsChecker();
601484
if (__tmp)
602485
__deleter_(__tmp);
603486
}
@@ -606,7 +489,6 @@ class _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS unique_ptr<_Tp[], _Dp>
606489
using std::swap;
607490
swap(__ptr_, __u.__ptr_);
608491
swap(__deleter_, __u.__deleter_);
609-
swap(__checker_, __u.__checker_);
610492
}
611493
};
612494

@@ -763,7 +645,7 @@ template <class _Tp>
763645
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 typename __unique_if<_Tp>::__unique_array_unknown_bound
764646
make_unique(size_t __n) {
765647
typedef __remove_extent_t<_Tp> _Up;
766-
return unique_ptr<_Tp>(__private_constructor_tag(), new _Up[__n](), __n);
648+
return unique_ptr<_Tp>(new _Up[__n]());
767649
}
768650

769651
template <class _Tp, class... _Args>
@@ -782,7 +664,7 @@ make_unique_for_overwrite() {
782664
template <class _Tp>
783665
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 typename __unique_if<_Tp>::__unique_array_unknown_bound
784666
make_unique_for_overwrite(size_t __n) {
785-
return unique_ptr<_Tp>(__private_constructor_tag(), new __remove_extent_t<_Tp>[__n], __n);
667+
return unique_ptr<_Tp>(new __remove_extent_t<_Tp>[__n]);
786668
}
787669

788670
template <class _Tp, class... _Args>

0 commit comments

Comments
 (0)