From 2310f352b825acd38fe9edd813b61c1b12d773de Mon Sep 17 00:00:00 2001 From: Michael Schellenberger Costa Date: Thu, 1 Jun 2023 14:59:29 +0200 Subject: [PATCH 1/2] Do not use inline variables pre C++17 --- include/cuda/memory_resource | 24 +++++++++---------- .../libcxx/include/__concepts/destructible.h | 4 ++-- .../libcxx/include/__concepts/movable.h | 2 +- .../libcxx/include/__functional/invoke.h | 2 +- .../libcxx/include/__mdspan/layout_left.h | 2 +- .../libcxx/include/__mdspan/layout_right.h | 2 +- .../libcxx/include/__mdspan/layout_stride.h | 2 +- .../detail/libcxx/include/__mdspan/mdspan.h | 6 ++--- .../include/__type_traits/common_reference.h | 17 ++++++------- .../cuda/std/detail/libcxx/include/cstddef | 10 ++++---- 10 files changed, 36 insertions(+), 35 deletions(-) diff --git a/include/cuda/memory_resource b/include/cuda/memory_resource index 804371a4be..0270294b08 100644 --- a/include/cuda/memory_resource +++ b/include/cuda/memory_resource @@ -235,7 +235,7 @@ _LIBCUDACXX_CONCEPT async_resource = _LIBCUDACXX_FRAGMENT(__async_resource_, _Re template #if _LIBCUDACXX_STD_VER < 17 _LIBCUDACXX_CONCEPT resource_with = - resource<_Resource>&& _CUDA_VSTD::conjunction_v<_CUDA_VSTD::bool_constant>...>; + resource<_Resource>&& _CUDA_VSTD::conjunction<_CUDA_VSTD::bool_constant>...>::value; #else _LIBCUDACXX_CONCEPT resource_with = resource<_Resource> && (has_property<_Resource, _Properties> && ...); #endif @@ -245,7 +245,7 @@ _LIBCUDACXX_CONCEPT resource_with = resource<_Resource> && (has_property<_Resour template #if _LIBCUDACXX_STD_VER < 17 _LIBCUDACXX_CONCEPT async_resource_with = async_resource<_Resource> && - _CUDA_VSTD::conjunction_v<_CUDA_VSTD::bool_constant>...>; + _CUDA_VSTD::conjunction<_CUDA_VSTD::bool_constant>...>::value; #else _LIBCUDACXX_CONCEPT async_resource_with = async_resource<_Resource> && (has_property<_Resource, _Properties> && ...); @@ -432,7 +432,7 @@ using _Filtered_vtable = typename _Filtered<_Properties...>::_Filtered_vtable::_ template struct _Alloc_base { - static_assert(cuda::std::is_base_of_v<_Alloc_vtable, _Vtable>, ""); + static_assert(_LIBCUDACXX_TRAIT(cuda::std::is_base_of, _Alloc_vtable, _Vtable), ""); _Alloc_base(void* __object_, const _Vtable* __static_vtabl_) noexcept : __object(__object_) @@ -457,7 +457,7 @@ protected: template struct _Async_alloc_base : public _Alloc_base<_Vtable> { - static_assert(cuda::std::is_base_of_v<_Async_alloc_vtable, _Vtable>, ""); + static_assert(_LIBCUDACXX_TRAIT(cuda::std::is_base_of, _Async_alloc_vtable, _Vtable), ""); _Async_alloc_base(void* __object_, const _Vtable* __static_vtabl_) noexcept : _Alloc_base<_Vtable>(__object_, __static_vtabl_) @@ -535,8 +535,8 @@ public: (requires (_CUDA_VSTD::_One_of<_Properties, _OtherProperties...> && ...)) #else _LIBCUDACXX_TEMPLATE(class... _OtherProperties) - (requires _CUDA_VSTD::conjunction_v<_CUDA_VSTD::bool_constant< - _CUDA_VSTD::_One_of<_Properties, _OtherProperties...>>...>) + (requires _CUDA_VSTD::conjunction<_CUDA_VSTD::bool_constant< + _CUDA_VSTD::_One_of<_Properties, _OtherProperties...>>...>::value) #endif basic_resource_ref( basic_resource_ref<_Alloc_type, _OtherProperties...> __ref) noexcept @@ -551,8 +551,8 @@ public: #else _LIBCUDACXX_TEMPLATE(class... _OtherProperties) (requires (_Alloc_type == _AllocType::_Default) - && _CUDA_VSTD::conjunction_v<_CUDA_VSTD::bool_constant< - _CUDA_VSTD::_One_of<_Properties, _OtherProperties...>>...>) + && _CUDA_VSTD::conjunction<_CUDA_VSTD::bool_constant< + _CUDA_VSTD::_One_of<_Properties, _OtherProperties...>>...>::value) #endif basic_resource_ref( basic_resource_ref<_AllocType::_Async, _OtherProperties...> __ref) noexcept @@ -567,8 +567,8 @@ public: #else _LIBCUDACXX_TEMPLATE(class... _OtherProperties) (requires (sizeof...(_Properties) == sizeof...(_OtherProperties)) - && _CUDA_VSTD::conjunction_v<_CUDA_VSTD::bool_constant< - _CUDA_VSTD::_One_of<_Properties, _OtherProperties...>>...>) + && _CUDA_VSTD::conjunction<_CUDA_VSTD::bool_constant< + _CUDA_VSTD::_One_of<_Properties, _OtherProperties...>>...>::value) #endif bool operator==( const basic_resource_ref<_Alloc_type, _OtherProperties...> &__right) const { @@ -583,8 +583,8 @@ public: #else _LIBCUDACXX_TEMPLATE(class... _OtherProperties) (requires (sizeof...(_Properties) == sizeof...(_OtherProperties)) - && _CUDA_VSTD::conjunction_v<_CUDA_VSTD::bool_constant< - _CUDA_VSTD::_One_of<_Properties, _OtherProperties...>>...>) + && _CUDA_VSTD::conjunction<_CUDA_VSTD::bool_constant< + _CUDA_VSTD::_One_of<_Properties, _OtherProperties...>>...>::value) #endif bool operator!=( const basic_resource_ref<_Alloc_type, _OtherProperties...> &__right) const { diff --git a/include/cuda/std/detail/libcxx/include/__concepts/destructible.h b/include/cuda/std/detail/libcxx/include/__concepts/destructible.h index 73fa3aca9b..f816788db5 100644 --- a/include/cuda/std/detail/libcxx/include/__concepts/destructible.h +++ b/include/cuda/std/detail/libcxx/include/__concepts/destructible.h @@ -27,7 +27,7 @@ _LIBCUDACXX_BEGIN_NAMESPACE_STD #if _LIBCUDACXX_STD_VER > 11 && _GNUC_VER < 1100 template -_LIBCUDACXX_CONCEPT destructible = is_nothrow_destructible_v<_Tp>; +_LIBCUDACXX_CONCEPT destructible = _LIBCUDACXX_TRAIT(is_nothrow_destructible, _Tp); #else // [concept.destructible] @@ -46,7 +46,7 @@ template _LIBCUDACXX_CONCEPT_FRAGMENT( __destructible_impl_req_, requires(_Tp& __t)( - requires(is_object_v<_Tp>), + requires(_LIBCUDACXX_TRAIT(is_object, _Tp)), requires(noexcept(__t.~_Tp())) )); diff --git a/include/cuda/std/detail/libcxx/include/__concepts/movable.h b/include/cuda/std/detail/libcxx/include/__concepts/movable.h index 8eb6042863..45fab98de9 100644 --- a/include/cuda/std/detail/libcxx/include/__concepts/movable.h +++ b/include/cuda/std/detail/libcxx/include/__concepts/movable.h @@ -42,7 +42,7 @@ template _LIBCUDACXX_CONCEPT_FRAGMENT( _Movable_, requires() - (requires(is_object_v<_Tp>), + (requires(_LIBCUDACXX_TRAIT(is_object, _Tp)), requires(move_constructible<_Tp>), requires(assignable_from<_Tp&, _Tp>), requires(swappable<_Tp>))); diff --git a/include/cuda/std/detail/libcxx/include/__functional/invoke.h b/include/cuda/std/detail/libcxx/include/__functional/invoke.h index 6def3acfbb..01d973868e 100644 --- a/include/cuda/std/detail/libcxx/include/__functional/invoke.h +++ b/include/cuda/std/detail/libcxx/include/__functional/invoke.h @@ -549,7 +549,7 @@ using invoke_result_t = typename invoke_result<_Fn, _Args...>::type; template _LIBCUDACXX_INLINE_VISIBILITY constexpr invoke_result_t<_Fn, _Args...> invoke(_Fn&& __f, _Args&&... __args) - noexcept(is_nothrow_invocable_v<_Fn, _Args...>) + noexcept(_LIBCUDACXX_TRAIT(is_nothrow_invocable, _Fn, _Args...)) { return _CUDA_VSTD::__invoke(_CUDA_VSTD::forward<_Fn>(__f), _CUDA_VSTD::forward<_Args>(__args)...); } diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/layout_left.h b/include/cuda/std/detail/libcxx/include/__mdspan/layout_left.h index c9d446b8c8..d127ac0d25 100644 --- a/include/cuda/std/detail/libcxx/include/__mdspan/layout_left.h +++ b/include/cuda/std/detail/libcxx/include/__mdspan/layout_left.h @@ -77,7 +77,7 @@ class layout_left::mapping { using layout_type = layout_left; private: - static_assert(__detail::__is_extents_v, "layout_left::mapping must be instantiated with a specialization of _CUDA_VSTD::extents."); + static_assert(__detail::__is_extents::value, "layout_left::mapping must be instantiated with a specialization of _CUDA_VSTD::extents."); template friend class mapping; diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/layout_right.h b/include/cuda/std/detail/libcxx/include/__mdspan/layout_right.h index 74ad81f92f..fced4b926c 100644 --- a/include/cuda/std/detail/libcxx/include/__mdspan/layout_right.h +++ b/include/cuda/std/detail/libcxx/include/__mdspan/layout_right.h @@ -77,7 +77,7 @@ class layout_right::mapping { using layout_type = layout_right; private: - static_assert(__detail::__is_extents_v, "layout_right::mapping must be instantiated with a specialization of _CUDA_VSTD::extents."); + static_assert(__detail::__is_extents::value, "layout_right::mapping must be instantiated with a specialization of _CUDA_VSTD::extents."); template friend class mapping; diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/layout_stride.h b/include/cuda/std/detail/libcxx/include/__mdspan/layout_stride.h index b5ef97af4d..62d35ec774 100644 --- a/include/cuda/std/detail/libcxx/include/__mdspan/layout_stride.h +++ b/include/cuda/std/detail/libcxx/include/__mdspan/layout_stride.h @@ -126,7 +126,7 @@ struct layout_stride { using layout_type = layout_stride; // This could be a `requires`, but I think it's better and clearer as a `static_assert`. - static_assert(__detail::__is_extents_v<_Extents>, "layout_stride::mapping must be instantiated with a specialization of _CUDA_VSTD::extents."); + static_assert(__detail::__is_extents<_Extents>::value, "layout_stride::mapping must be instantiated with a specialization of _CUDA_VSTD::extents."); private: diff --git a/include/cuda/std/detail/libcxx/include/__mdspan/mdspan.h b/include/cuda/std/detail/libcxx/include/__mdspan/mdspan.h index f5323a72ce..65ff881bb0 100644 --- a/include/cuda/std/detail/libcxx/include/__mdspan/mdspan.h +++ b/include/cuda/std/detail/libcxx/include/__mdspan/mdspan.h @@ -86,7 +86,7 @@ template < class mdspan { private: - static_assert(__detail::__is_extents_v<_Extents>, "mdspan's Extents template parameter must be a specialization of _CUDA_VSTD::extents."); + static_assert(__detail::__is_extents<_Extents>::value, "mdspan's Extents template parameter must be a specialization of _CUDA_VSTD::extents."); // Workaround for non-deducibility of the index sequence template parameter if it's given at the top level template @@ -431,9 +431,9 @@ __MDSPAN_TEMPLATE_REQUIRES( mdspan(_Pointer&&) -> mdspan<_CUDA_VSTD::remove_pointer_t<_CUDA_VSTD::remove_reference_t<_Pointer>>, extents>; __MDSPAN_TEMPLATE_REQUIRES( class _CArray, - (_LIBCUDACXX_TRAIT(is_array, _CArray) && (rank_v<_CArray> == 1)) + (_LIBCUDACXX_TRAIT(is_array, _CArray) && (_LIBCUDACXX_TRAIT(rank, _CArray) == 1)) ) -mdspan(_CArray&) -> mdspan<_CUDA_VSTD::remove_all_extents_t<_CArray>, extents>>; +mdspan(_CArray&) -> mdspan<_CUDA_VSTD::remove_all_extents_t<_CArray>, extents>; template mdspan(_ElementType*, const _CUDA_VSTD::array<_SizeType, _Np>&) diff --git a/include/cuda/std/detail/libcxx/include/__type_traits/common_reference.h b/include/cuda/std/detail/libcxx/include/__type_traits/common_reference.h index 3ced497607..91fea45a42 100644 --- a/include/cuda/std/detail/libcxx/include/__type_traits/common_reference.h +++ b/include/cuda/std/detail/libcxx/include/__type_traits/common_reference.h @@ -54,9 +54,10 @@ struct __cond_res_workaround {}; template struct __cond_res_workaround<_Tp, _Up, void_t<__cond_res_if_right<_Tp, _Up>>> { using _RTp = remove_cvref_t<_Tp>; - using type = conditional_t> && - (is_scalar_v<_RTp> || is_array_v<_RTp>) && - ((is_lvalue_reference_v<_Tp> && is_rvalue_reference_v<_Up>) || (is_rvalue_reference_v<_Tp> && is_lvalue_reference_v<_Up>)), + using type = conditional_t<_LIBCUDACXX_TRAIT(is_same, _RTp, remove_cvref_t<_Up>) + && (_LIBCUDACXX_TRAIT(is_scalar, _RTp) || _LIBCUDACXX_TRAIT(is_array, _RTp)) + && ((_LIBCUDACXX_TRAIT(is_lvalue_reference, _Tp) && _LIBCUDACXX_TRAIT(is_rvalue_reference, _Up)) + ||(_LIBCUDACXX_TRAIT(is_rvalue_reference, _Tp) && _LIBCUDACXX_TRAIT(is_lvalue_reference, _Up))), decay_t<__copy_cv_t, remove_reference_t<_Up>>>, __cond_res_if_right<_Tp, _Up>>; }; @@ -93,7 +94,7 @@ using __cv_cond_res = __cond_res<__copy_cv_t<_Xp, _Yp>&, __copy_cv_t<_Yp, _Xp>&> // If A and B are both lvalue reference types, COMMON-REF(A, B) is // COND-RES(COPYCV(X, Y)&, COPYCV(Y, X)&) if that type exists and is a reference type. template -struct __common_ref<_Ap&, _Bp&, enable_if_t>>> +struct __common_ref<_Ap&, _Bp&, enable_if_t<_LIBCUDACXX_TRAIT(is_reference, __cv_cond_res<_Ap, _Bp>)>> { using __type = __cv_cond_res<_Ap, _Bp>; }; @@ -110,8 +111,8 @@ struct __common_ref_rr {}; template struct __common_ref_rr<_Ap&&, _Bp&&, enable_if_t< - is_convertible_v<_Ap&&, __common_ref_C<_Ap, _Bp>> - && is_convertible_v<_Bp&&, __common_ref_C<_Ap, _Bp>>>> + _LIBCUDACXX_TRAIT(is_convertible, _Ap&&, __common_ref_C<_Ap, _Bp>) + && _LIBCUDACXX_TRAIT(is_convertible, _Bp&&, __common_ref_C<_Ap, _Bp>)>> { using __type = __common_ref_C<_Ap, _Bp>; }; @@ -129,7 +130,7 @@ template struct __common_ref_lr {}; template -struct __common_ref_lr<_Ap&&, _Bp&, enable_if_t>>> +struct __common_ref_lr<_Ap&&, _Bp&, enable_if_t<_LIBCUDACXX_TRAIT(is_convertible, _Ap&&, __common_ref_D<_Ap, _Bp>)>> { using __type = __common_ref_D<_Ap, _Bp>; }; @@ -178,7 +179,7 @@ template struct common_reference<_Tp, _Up> : __common_ref template struct __common_reference_sub_bullet1<_Tp, _Up, void_t<__common_ref_t<_Tp, _Up>, - enable_if_t && is_reference_v<_Up>>>> + enable_if_t<_LIBCUDACXX_TRAIT(is_reference, _Tp) && _LIBCUDACXX_TRAIT(is_reference, _Up)>>> { using type = __common_ref_t<_Tp, _Up>; }; diff --git a/include/cuda/std/detail/libcxx/include/cstddef b/include/cuda/std/detail/libcxx/include/cstddef index da6f561041..6968e59121 100644 --- a/include/cuda/std/detail/libcxx/include/cstddef +++ b/include/cuda/std/detail/libcxx/include/cstddef @@ -136,31 +136,31 @@ constexpr byte operator~ (byte __b) noexcept template _LIBCUDACXX_INLINE_VISIBILITY - constexpr __enable_if_t, byte> & + constexpr __enable_if_t<_LIBCUDACXX_TRAIT(is_integral, _Integer), byte> & operator<<=(byte& __lhs, _Integer __shift) noexcept { return __lhs = __lhs << __shift; } template _LIBCUDACXX_INLINE_VISIBILITY - constexpr __enable_if_t, byte> + constexpr __enable_if_t<_LIBCUDACXX_TRAIT(is_integral, _Integer), byte> operator<< (byte __lhs, _Integer __shift) noexcept { return static_cast(static_cast(static_cast(__lhs) << __shift)); } template _LIBCUDACXX_INLINE_VISIBILITY - constexpr __enable_if_t, byte> & + constexpr __enable_if_t<_LIBCUDACXX_TRAIT(is_integral, _Integer), byte> & operator>>=(byte& __lhs, _Integer __shift) noexcept { return __lhs = __lhs >> __shift; } template _LIBCUDACXX_INLINE_VISIBILITY - constexpr __enable_if_t, byte> + constexpr __enable_if_t<_LIBCUDACXX_TRAIT(is_integral, _Integer), byte> operator>> (byte __lhs, _Integer __shift) noexcept { return static_cast(static_cast(static_cast(__lhs) >> __shift)); } template _LIBCUDACXX_INLINE_VISIBILITY - constexpr __enable_if_t, _Integer> + constexpr __enable_if_t<_LIBCUDACXX_TRAIT(is_integral, _Integer), _Integer> to_integer(byte __b) noexcept { return static_cast<_Integer>(__b); } #ifdef _LIBCUDACXX_END_NAMESPACE_STD_NOVERSION From 5fb1da24aeb0b626cbb5ed68081bb63afec21ce3 Mon Sep 17 00:00:00 2001 From: Michael Schellenberger Costa Date: Fri, 2 Jun 2023 10:24:39 +0200 Subject: [PATCH 2/2] Rework the `destructible` implementation to not rely on inline variables in C++14 --- .../libcxx/include/__concepts/destructible.h | 60 ++++++++++++++----- 1 file changed, 44 insertions(+), 16 deletions(-) diff --git a/include/cuda/std/detail/libcxx/include/__concepts/destructible.h b/include/cuda/std/detail/libcxx/include/__concepts/destructible.h index f816788db5..b4d11ba13f 100644 --- a/include/cuda/std/detail/libcxx/include/__concepts/destructible.h +++ b/include/cuda/std/detail/libcxx/include/__concepts/destructible.h @@ -24,23 +24,27 @@ _LIBCUDACXX_BEGIN_NAMESPACE_STD -#if _LIBCUDACXX_STD_VER > 11 && _GNUC_VER < 1100 +#if _LIBCUDACXX_STD_VER > 11 + +// [concept.destructible] + +#if defined(_LIBCUDACXX_COMPILER_GCC) && _GNUC_VER < 1100 template _LIBCUDACXX_CONCEPT destructible = _LIBCUDACXX_TRAIT(is_nothrow_destructible, _Tp); -#else -// [concept.destructible] -#if _LIBCUDACXX_STD_VER > 17 +#else // ^^^ _LIBCUDACXX_COMPILER_GCC && GCC < 11 ^^^ / vvv other compilers vvv + +#if _LIBCUDACXX_STD_VER > 17 // use concepts template -constexpr bool __destructible_impl = false; +inline constexpr bool __destructible_impl_v = false; template requires requires(_Tp& __t) { { __t.~_Tp() } noexcept; } -constexpr bool __destructible_impl<_Tp> = true; +inline constexpr bool __destructible_impl_v<_Tp> = true; -#elif _LIBCUDACXX_STD_VER > 11 +#else // ^^^ _LIBCUDACXX_STD_VER > 17 ^^^ / vvv _LIBCUDACXX_STD_VER < 20 vvv template _LIBCUDACXX_CONCEPT_FRAGMENT( @@ -51,27 +55,51 @@ _LIBCUDACXX_CONCEPT_FRAGMENT( )); template -constexpr bool __destructible_impl = _LIBCUDACXX_FRAGMENT(__destructible_impl_req_, _Tp); -#endif // _LIBCUDACXX_STD_VER > 11 +struct __destructible_impl : public _BoolConstant<_LIBCUDACXX_FRAGMENT(__destructible_impl_req_, _Tp)> {}; + +#if _LIBCUDACXX_STD_VER > 14 +template +inline constexpr bool __destructible_impl_v = _LIBCUDACXX_FRAGMENT(__destructible_impl_req_, _Tp); +#endif // _LIBCUDACXX_STD_VER > 14 + +#endif // _LIBCUDACXX_STD_VER < 20 + +#if _LIBCUDACXX_STD_VER > 14 // inline variables -#if _LIBCUDACXX_STD_VER > 11 template -constexpr bool __destructible = __destructible_impl<_Tp>; +inline constexpr bool __destructible_v = __destructible_impl_v<_Tp>; template -constexpr bool __destructible<_Tp&> = true; +inline constexpr bool __destructible_v<_Tp&> = true; template -constexpr bool __destructible<_Tp&&> = true; +inline constexpr bool __destructible_v<_Tp&&> = true; template -constexpr bool __destructible<_Tp[_Nm]> = __destructible<_Tp>; +inline constexpr bool __destructible_v<_Tp[_Nm]> = __destructible_v<_Tp>; + +#else // ^^^ _LIBCUDACXX_STD_VER > 14 ^^^ / vvv _LIBCUDACXX_STD_VER < 17 vvv + +template +struct __destructible : public __destructible_impl<_Tp> {}; template -_LIBCUDACXX_CONCEPT destructible = __destructible<_Tp>; +struct __destructible<_Tp&> : public true_type {}; + +template +struct __destructible<_Tp&&> : public true_type {}; + +template +struct __destructible<_Tp[_Nm]> : public __destructible<_Tp> {}; + +#endif // _LIBCUDACXX_STD_VER < 17 + +template +_LIBCUDACXX_CONCEPT destructible = _LIBCUDACXX_TRAIT(__destructible, _Tp); + +#endif // !_LIBCUDACXX_COMPILER_GCC || __GNUC__ > 11 #endif // _LIBCUDACXX_STD_VER > 11 -#endif // _GNUC_VER < 1100 _LIBCUDACXX_END_NAMESPACE_STD