[libcxx-commits] [libcxx] e12d8f5 - [libc++][PSTL] Replace _PSTL_ASSERT with _LIBCPP_ASSERT

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Thu May 4 11:42:56 PDT 2023


Author: Nikolas Klauser
Date: 2023-05-04T11:42:50-07:00
New Revision: e12d8f597bde492a20fe1a1a31bb67b7012f39ba

URL: https://github.com/llvm/llvm-project/commit/e12d8f597bde492a20fe1a1a31bb67b7012f39ba
DIFF: https://github.com/llvm/llvm-project/commit/e12d8f597bde492a20fe1a1a31bb67b7012f39ba.diff

LOG: [libc++][PSTL] Replace _PSTL_ASSERT with _LIBCPP_ASSERT

Reviewed By: ldionne, #libc

Spies: libcxx-commits

Differential Revision: https://reviews.llvm.org/D149605

Added: 
    

Modified: 
    libcxx/include/__pstl/internal/algorithm_impl.h
    libcxx/include/__pstl/internal/numeric_impl.h
    libcxx/include/__pstl/internal/parallel_backend_tbb.h
    libcxx/include/__pstl/internal/parallel_backend_utils.h
    libcxx/include/__pstl/internal/pstl_config.h

Removed: 
    


################################################################################
diff  --git a/libcxx/include/__pstl/internal/algorithm_impl.h b/libcxx/include/__pstl/internal/algorithm_impl.h
index 6d5a737f2d7b..1f51651065f2 100644
--- a/libcxx/include/__pstl/internal/algorithm_impl.h
+++ b/libcxx/include/__pstl/internal/algorithm_impl.h
@@ -10,6 +10,7 @@
 #ifndef _PSTL_ALGORITHM_IMPL_H
 #define _PSTL_ALGORITHM_IMPL_H
 
+#include <__assert>
 #include <algorithm>
 #include <functional>
 #include <iterator>
@@ -3093,8 +3094,8 @@ bool __pattern_includes(
         __first2,
         __last2,
         [__first1, __last1, __first2, __last2, &__comp](_RandomAccessIterator2 __i, _RandomAccessIterator2 __j) {
-          _PSTL_ASSERT(__j > __i);
-          //_PSTL_ASSERT(__j - __i > 1);
+          _LIBCPP_ASSERT(__j > __i, "");
+          //_LIBCPP_ASSERT(__j - __i > 1, "");
 
           // 1. moving boundaries to "consume" subsequence of equal elements
           auto __is_equal = [&__comp](_RandomAccessIterator2 __a, _RandomAccessIterator2 __b) -> bool {
@@ -3117,8 +3118,8 @@ bool __pattern_includes(
           // 2. testing is __a subsequence of the second range included into the first range
           auto __b = std::lower_bound(__first1, __last1, *__i, __comp);
 
-          _PSTL_ASSERT(!__comp(*(__last1 - 1), *__b));
-          _PSTL_ASSERT(!__comp(*(__j - 1), *__i));
+          _LIBCPP_ASSERT(!__comp(*(__last1 - 1), *__b), "");
+          _LIBCPP_ASSERT(!__comp(*(__j - 1), *__i), "");
           return !std::includes(__b, __last1, __i, __j, __comp);
         });
   });
@@ -3335,7 +3336,7 @@ _OutputIterator __parallel_set_union_op(
   }
 
   const auto __m2 = __left_bound_seq_2 - __first2;
-  _PSTL_ASSERT(__m1 == 0 || __m2 == 0);
+  _LIBCPP_ASSERT(__m1 == 0 || __m2 == 0, "");
   if (__m2 > __set_algo_cut_off) {
     auto __res_or = __result;
     __result += __m2; // we know proper offset due to [first2; left_bound_seq_2) < [first1; last1)

diff  --git a/libcxx/include/__pstl/internal/numeric_impl.h b/libcxx/include/__pstl/internal/numeric_impl.h
index eb7603ab118e..7c852d7b0825 100644
--- a/libcxx/include/__pstl/internal/numeric_impl.h
+++ b/libcxx/include/__pstl/internal/numeric_impl.h
@@ -10,6 +10,7 @@
 #ifndef _PSTL_NUMERIC_IMPL_H
 #define _PSTL_NUMERIC_IMPL_H
 
+#include <__assert>
 #include <iterator>
 #include <type_traits>
 #include <numeric>
@@ -466,7 +467,7 @@ _RandomAccessIterator2 __brick_adjacent_
diff erence(
     _RandomAccessIterator2 __d_first,
     BinaryOperation __op,
     /*is_vector=*/std::true_type) noexcept {
-  _PSTL_ASSERT(__first != __last);
+  _LIBCPP_ASSERT(__first != __last, "Range cannot be empty");
 
   typedef typename std::iterator_traits<_RandomAccessIterator1>::reference _ReferenceType1;
   typedef typename std::iterator_traits<_RandomAccessIterator2>::reference _ReferenceType2;
@@ -504,7 +505,7 @@ _RandomAccessIterator2 __pattern_adjacent_
diff erence(
     _RandomAccessIterator1 __last,
     _RandomAccessIterator2 __d_first,
     _BinaryOperation __op) {
-  _PSTL_ASSERT(__first != __last);
+  _LIBCPP_ASSERT(__first != __last, "range cannot be empty");
   typedef typename std::iterator_traits<_RandomAccessIterator1>::reference _ReferenceType1;
   typedef typename std::iterator_traits<_RandomAccessIterator2>::reference _ReferenceType2;
 

diff  --git a/libcxx/include/__pstl/internal/parallel_backend_tbb.h b/libcxx/include/__pstl/internal/parallel_backend_tbb.h
index aa088646495f..3bee7e2764e1 100644
--- a/libcxx/include/__pstl/internal/parallel_backend_tbb.h
+++ b/libcxx/include/__pstl/internal/parallel_backend_tbb.h
@@ -10,6 +10,7 @@
 #ifndef _PSTL_PARALLEL_BACKEND_TBB_H
 #define _PSTL_PARALLEL_BACKEND_TBB_H
 
+#include <__assert>
 #include <algorithm>
 #include <type_traits>
 
@@ -526,7 +527,7 @@ class __task : public tbb::detail::d1::task
     __task*
     allocate_func_task(_Fn&& __f)
     {
-        _PSTL_ASSERT(_M_execute_data != nullptr);
+        _LIBCPP_ASSERT(_M_execute_data != nullptr, "");
         tbb::detail::d1::small_object_allocator __alloc{};
         auto __t =
             __alloc.new_object<__func_task<typename std::decay<_Fn>::type>>(*_M_execute_data, std::forward<_Fn>(__f));
@@ -571,7 +572,7 @@ class __task : public tbb::detail::d1::task
     make_additional_child_of(__task* __parent, _Fn&& __f)
     {
         auto __t = make_child_of(__parent, std::forward<_Fn>(__f));
-        _PSTL_ASSERT(__parent->_M_refcount.load(std::memory_order_relaxed) > 0);
+        _LIBCPP_ASSERT(__parent->_M_refcount.load(std::memory_order_relaxed) > 0, "");
         ++__parent->_M_refcount;
         return __t;
     }
@@ -592,7 +593,7 @@ class __task : public tbb::detail::d1::task
     inline void
     spawn(__task* __t)
     {
-        _PSTL_ASSERT(_M_execute_data != nullptr);
+        _LIBCPP_ASSERT(_M_execute_data != nullptr, "");
         tbb::detail::d1::spawn(*__t, *_M_execute_data->context);
     }
 
@@ -645,11 +646,11 @@ class __func_task : public __task
 
         this->~__func_task();
 
-        _PSTL_ASSERT(__parent != nullptr);
-        _PSTL_ASSERT(__parent->_M_refcount.load(std::memory_order_relaxed) > 0);
+        _LIBCPP_ASSERT(__parent != nullptr, "");
+        _LIBCPP_ASSERT(__parent->_M_refcount.load(std::memory_order_relaxed) > 0, "");
         if (--__parent->_M_refcount == 0)
         {
-            _PSTL_ASSERT(__next == nullptr);
+            _LIBCPP_ASSERT(__next == nullptr, "");
             __alloc.deallocate(this, *__ed);
             return __parent;
         }
@@ -861,20 +862,20 @@ class __merge_func
     {
         const auto __nx = (_M_xe - _M_xs);
         const auto __ny = (_M_ye - _M_ys);
-        _PSTL_ASSERT(__nx > 0 && __ny > 0);
+        _LIBCPP_ASSERT(__nx > 0 && __ny > 0, "");
 
-        _PSTL_ASSERT(_x_orig == _y_orig);
-        _PSTL_ASSERT(!is_partial());
+        _LIBCPP_ASSERT(_x_orig == _y_orig, "");
+        _LIBCPP_ASSERT(!is_partial(), "");
 
         if (_x_orig)
         {
-            _PSTL_ASSERT(std::is_sorted(_M_x_beg + _M_xs, _M_x_beg + _M_xe, _M_comp));
-            _PSTL_ASSERT(std::is_sorted(_M_x_beg + _M_ys, _M_x_beg + _M_ye, _M_comp));
+            _LIBCPP_ASSERT(std::is_sorted(_M_x_beg + _M_xs, _M_x_beg + _M_xe, _M_comp), "");
+            _LIBCPP_ASSERT(std::is_sorted(_M_x_beg + _M_ys, _M_x_beg + _M_ye, _M_comp), "");
             return !_M_comp(*(_M_x_beg + _M_ys), *(_M_x_beg + _M_xe - 1));
         }
 
-        _PSTL_ASSERT(std::is_sorted(_M_z_beg + _M_xs, _M_z_beg + _M_xe, _M_comp));
-        _PSTL_ASSERT(std::is_sorted(_M_z_beg + _M_ys, _M_z_beg + _M_ye, _M_comp));
+        _LIBCPP_ASSERT(std::is_sorted(_M_z_beg + _M_xs, _M_z_beg + _M_xe, _M_comp), "");
+        _LIBCPP_ASSERT(std::is_sorted(_M_z_beg + _M_ys, _M_z_beg + _M_ye, _M_comp), "");
         return !_M_comp(*(_M_z_beg + _M_zs + __nx), *(_M_z_beg + _M_zs + __nx - 1));
     }
     void
@@ -882,7 +883,7 @@ class __merge_func
     {
         const auto __nx = (_M_xe - _M_xs);
         const auto __ny = (_M_ye - _M_ys);
-        _PSTL_ASSERT(__nx > 0 && __ny > 0);
+        _LIBCPP_ASSERT(__nx > 0 && __ny > 0, "");
 
         if (_x_orig)
             __move_range_construct()(_M_x_beg + _M_xs, _M_x_beg + _M_xe, _M_z_beg + _M_zs);
@@ -913,7 +914,7 @@ class __merge_func
     __task*
     merge_ranges(__task* __self)
     {
-        _PSTL_ASSERT(_x_orig == _y_orig); //two merged subrange must be lie into the same buffer
+        _LIBCPP_ASSERT(_x_orig == _y_orig, ""); //two merged subrange must be lie into the same buffer
 
         const auto __nx = (_M_xe - _M_xs);
         const auto __ny = (_M_ye - _M_ys);
@@ -929,15 +930,15 @@ class __merge_func
             _M_leaf_merge(_M_x_beg + _M_xs, _M_x_beg + _M_xe, _M_x_beg + _M_ys, _M_x_beg + _M_ye, _M_z_beg + _M_zs,
                           _M_comp, __move_value_construct(), __move_value_construct(), __move_range_construct(),
                           __move_range_construct());
-            _PSTL_ASSERT(parent_merge(__self)); //not root merging task
+            _LIBCPP_ASSERT(parent_merge(__self), ""); //not root merging task
         }
         //merge to "origin"
         else
         {
-            _PSTL_ASSERT(_x_orig == _y_orig);
+            _LIBCPP_ASSERT(_x_orig == _y_orig, "");
 
-            _PSTL_ASSERT(is_partial() || std::is_sorted(_M_z_beg + _M_xs, _M_z_beg + _M_xe, _M_comp));
-            _PSTL_ASSERT(is_partial() || std::is_sorted(_M_z_beg + _M_ys, _M_z_beg + _M_ye, _M_comp));
+            _LIBCPP_ASSERT(is_partial() || std::is_sorted(_M_z_beg + _M_xs, _M_z_beg + _M_xe, _M_comp), "");
+            _LIBCPP_ASSERT(is_partial() || std::is_sorted(_M_z_beg + _M_ys, _M_z_beg + _M_ye, _M_comp), "");
 
             const auto __nx = (_M_xe - _M_xs);
             const auto __ny = (_M_ye - _M_ys);
@@ -954,8 +955,8 @@ class __merge_func
     __task*
     process_ranges(__task* __self)
     {
-        _PSTL_ASSERT(_x_orig == _y_orig);
-        _PSTL_ASSERT(!_split);
+        _LIBCPP_ASSERT(_x_orig == _y_orig, "");
+        _LIBCPP_ASSERT(!_split, "");
 
         auto p = parent_merge(__self);
 
@@ -1001,7 +1002,7 @@ class __merge_func
     __task*
     split_merging(__task* __self)
     {
-        _PSTL_ASSERT(_x_orig == _y_orig);
+        _LIBCPP_ASSERT(_x_orig == _y_orig, "");
         const auto __nx = (_M_xe - _M_xs);
         const auto __ny = (_M_ye - _M_ys);
 
@@ -1073,8 +1074,8 @@ operator()(__task* __self)
     {
         const _SizeType __nx = (_M_xe - _M_xs);
         const _SizeType __ny = (_M_ye - _M_ys);
-        _PSTL_ASSERT(__nx > 0);
-        _PSTL_ASSERT(__nx > 0);
+        _LIBCPP_ASSERT(__nx > 0, "");
+        _LIBCPP_ASSERT(__nx > 0, "");
 
         if (__nx < __ny)
             move_x_range();
@@ -1130,7 +1131,7 @@ __stable_sort_func<_RandomAccessIterator1, _RandomAccessIterator2, _Compare, _Le
     if (__n <= __sort_cut_off)
     {
         _M_leaf_sort(_M_xs, _M_xe, _M_comp);
-        _PSTL_ASSERT(!_M_root);
+        _LIBCPP_ASSERT(!_M_root, "");
         return nullptr;
     }
 

diff  --git a/libcxx/include/__pstl/internal/parallel_backend_utils.h b/libcxx/include/__pstl/internal/parallel_backend_utils.h
index 177717f28499..b27d1ef2b1ce 100644
--- a/libcxx/include/__pstl/internal/parallel_backend_utils.h
+++ b/libcxx/include/__pstl/internal/parallel_backend_utils.h
@@ -10,6 +10,7 @@
 #ifndef _PSTL_PARALLEL_BACKEND_UTILS_H
 #define _PSTL_PARALLEL_BACKEND_UTILS_H
 
+#include <__assert>
 #include <__iterator/iterator_traits.h>
 #include <__memory/addressof.h>
 
@@ -56,7 +57,7 @@ struct __serial_move_merge
         constexpr bool __same_move_seq = std::is_same<_MoveSequenceX, _MoveSequenceY>::value;
 
         auto __n = _M_nmerge;
-        _PSTL_ASSERT(__n > 0);
+        _LIBCPP_ASSERT(__n > 0, "");
 
         auto __nx = __xe - __xs;
         //auto __ny = __ye - __ys;

diff  --git a/libcxx/include/__pstl/internal/pstl_config.h b/libcxx/include/__pstl/internal/pstl_config.h
index 090dfc70cb9c..763d1399764a 100644
--- a/libcxx/include/__pstl/internal/pstl_config.h
+++ b/libcxx/include/__pstl/internal/pstl_config.h
@@ -15,9 +15,6 @@
 // TODO: Make this a proper configuration option
 #define _PSTL_PAR_BACKEND_SERIAL
 
-#include <__assert>
-#define _PSTL_ASSERT(pred) _LIBCPP_ASSERT(pred, "")
-
 #define _PSTL_PRAGMA(x) _Pragma(#    x)
 
 // Enable SIMD for compilers that support OpenMP 4.0


        


More information about the libcxx-commits mailing list