From 21907a452ac59bef11953af82e295b2806205ee2 Mon Sep 17 00:00:00 2001 From: Eric Niebler Date: Thu, 19 Dec 2024 11:26:51 -0800 Subject: [PATCH 1/8] help the ranges concepts recognize standard contiguous iterators in c++17 --- .../cuda/experimental/__algorithm/common.cuh | 20 +---- .../cuda/std/__iterator/iterator_traits.h | 87 +++++++++++++------ 2 files changed, 63 insertions(+), 44 deletions(-) diff --git a/cudax/include/cuda/experimental/__algorithm/common.cuh b/cudax/include/cuda/experimental/__algorithm/common.cuh index eadb5e50dd5..f79a9ebc926 100644 --- a/cudax/include/cuda/experimental/__algorithm/common.cuh +++ b/cudax/include/cuda/experimental/__algorithm/common.cuh @@ -31,26 +31,8 @@ namespace cuda::experimental { -#if _CCCL_STD_VER >= 2020 && defined(_CCCL_SPAN_USES_RANGES) template -concept __valid_1d_copy_fill_argument = _CUDA_VRANGES::contiguous_range>; - -#else -template -inline constexpr bool __convertible_to_span = false; - -template -inline constexpr bool __convertible_to_span< - _Tp, - _CUDA_VSTD::enable_if_t< - _CUDA_VSTD::is_convertible_v<_Tp, _CUDA_VSTD::span::value_type>>, - int>> = true; - -template -inline constexpr bool __valid_1d_copy_fill_argument = - _CUDA_VRANGES::contiguous_range> || __convertible_to_span<_Tp>; - -#endif +_CCCL_CONCEPT __valid_1d_copy_fill_argument = _CUDA_VRANGES::contiguous_range>; template > using __as_mdspan_t = diff --git a/libcudacxx/include/cuda/std/__iterator/iterator_traits.h b/libcudacxx/include/cuda/std/__iterator/iterator_traits.h index 020f27071db..143a7ae9691 100644 --- a/libcudacxx/include/cuda/std/__iterator/iterator_traits.h +++ b/libcudacxx/include/cuda/std/__iterator/iterator_traits.h @@ -37,6 +37,7 @@ #include #include #include +#include #include #if !_CCCL_COMPILER(NVRTC) @@ -46,6 +47,10 @@ # include // for ::std::input_iterator_tag # endif // !_CCCL_COMPILER(MSVC) +# ifdef _GLIBCXX_DEBUG +# include +# endif + # if _CCCL_STD_VER >= 2020 template struct __cccl_type_is_defined : _CUDA_VSTD::false_type @@ -109,7 +114,7 @@ _CCCL_CONCEPT __dereferenceable = _CCCL_FRAGMENT(__dereferenceable_, _Tp); // [iterator.traits] template -using iter_reference_t = enable_if_t<__dereferenceable<_Tp>, decltype(*_CUDA_VSTD::declval<_Tp&>())>; +using iter_reference_t = enable_if_t<__dereferenceable<_Tp>, decltype(*declval<_Tp&>())>; template struct _CCCL_TYPE_VISIBILITY_DEFAULT iterator_traits; @@ -165,38 +170,70 @@ struct __iter_traits_cache template using _ITER_TRAITS = typename __iter_traits_cache<_Iter>::type; -struct __iter_concept_concept_test -{ - template - using _Apply = typename _ITER_TRAITS<_Iter>::iterator_concept; -}; -struct __iter_concept_category_test -{ - template - using _Apply = typename _ITER_TRAITS<_Iter>::iterator_category; -}; -struct __iter_concept_random_fallback -{ - template - using _Apply = enable_if_t<__is_primary_template>::value, random_access_iterator_tag>; -}; +#if defined(_GLIBCXX_DEBUG) +_CCCL_TEMPLATE(class _Iter, class _Ty, class _Range) +_CCCL_REQUIRES(same_as<_Iter, ::__gnu_debug::_Safe_iterator<_Ty*, _Range>>) +auto __iter_concept_fn(::__gnu_debug::_Safe_iterator<_Ty*, _Range>, __priority_tag<3>) -> contiguous_iterator_tag; +#endif +#if defined(__GLIBCXX__) +_CCCL_TEMPLATE(class _Iter, class _Ty, class _Range) +_CCCL_REQUIRES(same_as<_Iter, ::__gnu_cxx::__normal_iterator<_Ty*, _Range>>) +auto __iter_concept_fn(::__gnu_cxx::__normal_iterator<_Ty*, _Range>, __priority_tag<3>) -> contiguous_iterator_tag; +#endif +#if defined(_LIBCPP_VERSION) +_CCCL_TEMPLATE(class _Iter, class _Ty) +_CCCL_REQUIRES(same_as<_Iter, ::std::__wrap_iter<_Ty*>>) +auto __iter_concept_fn(::std::__wrap_iter<_Ty*>, __priority_tag<3>) -> contiguous_iterator_tag; +#endif +#if defined(_MSVC_STL_VERSION) || defined(_IS_WRS) +_CCCL_TEMPLATE(class _Iter) +_CCCL_REQUIRES(same_as<_Iter, class _Iter::_Array_iterator>) +auto __iter_concept_fn(_Iter, __priority_tag<3>) -> contiguous_iterator_tag; +_CCCL_TEMPLATE(class _Iter) +_CCCL_REQUIRES(same_as<_Iter, class _Iter::_Array_const_iterator>) +auto __iter_concept_fn(_Iter, __priority_tag<3>) -> contiguous_iterator_tag; +_CCCL_TEMPLATE(class _Iter) +_CCCL_REQUIRES(same_as<_Iter, class _Iter::_Vector_iterator>) +auto __iter_concept_fn(_Iter, __priority_tag<3>) -> contiguous_iterator_tag; +_CCCL_TEMPLATE(class _Iter) +_CCCL_REQUIRES(same_as<_Iter, class _Iter::_Vector_const_iterator>) +auto __iter_concept_fn(_Iter, __priority_tag<3>) -> contiguous_iterator_tag; +_CCCL_TEMPLATE(class _Iter) +_CCCL_REQUIRES(same_as<_Iter, class _Iter::_String_iterator>) +auto __iter_concept_fn(_Iter, __priority_tag<3>) -> contiguous_iterator_tag; +_CCCL_TEMPLATE(class _Iter) +_CCCL_REQUIRES(same_as<_Iter, class _Iter::_String_const_iterator>) +auto __iter_concept_fn(_Iter, __priority_tag<3>) -> contiguous_iterator_tag; +_CCCL_TEMPLATE(class _Iter) +_CCCL_REQUIRES(same_as<_Iter, class _Iter::_String_view_iterator>) +auto __iter_concept_fn(_Iter, __priority_tag<3>) -> contiguous_iterator_tag; +#endif +_CCCL_TEMPLATE(class _Iter, class _Ty) +_CCCL_REQUIRES(same_as<_Iter, _Ty*>) +auto __iter_concept_fn(_Ty*, __priority_tag<3>) -> contiguous_iterator_tag; +template +auto __iter_concept_fn(_Iter, __priority_tag<2>) -> class _ITER_TRAITS<_Iter>::iterator_concept; +template +auto __iter_concept_fn(_Iter, __priority_tag<1>) -> class _ITER_TRAITS<_Iter>::iterator_category; +template +auto __iter_concept_fn(_Iter, __priority_tag<0>) + -> enable_if_t<__is_primary_template>::value, random_access_iterator_tag>; -template -struct __test_iter_concept - : _IsValidExpansion<_Tester::template _Apply, _Iter> - , _Tester +template +using __iter_concept_t = decltype(_CUDA_VSTD::__iter_concept_fn<_Iter>(declval<_Iter>(), __priority_tag<3>{})); + +template +struct __iter_concept_cache {}; template -struct __iter_concept_cache +struct __iter_concept_cache<_Iter, void_t<__iter_concept_t<_Iter>>> { - using type = _Or<__test_iter_concept<_Iter, __iter_concept_concept_test>, - __test_iter_concept<_Iter, __iter_concept_category_test>, - __test_iter_concept<_Iter, __iter_concept_random_fallback>>; + using type = __iter_concept_t<_Iter>; }; template -using _ITER_CONCEPT = typename __iter_concept_cache<_Iter>::type::template _Apply<_Iter>; +using _ITER_CONCEPT = typename __iter_concept_cache<_Iter>::type; template struct __has_iterator_typedefs From e16f081fffd8f9148980a2ddce97b70604628f37 Mon Sep 17 00:00:00 2001 From: Eric Niebler Date: Thu, 19 Dec 2024 12:48:21 -0800 Subject: [PATCH 2/8] `same_as` doesn't exist in C++11 --- .../cuda/std/__iterator/iterator_traits.h | 54 ++++++++++--------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/libcudacxx/include/cuda/std/__iterator/iterator_traits.h b/libcudacxx/include/cuda/std/__iterator/iterator_traits.h index 143a7ae9691..bddf5ad563b 100644 --- a/libcudacxx/include/cuda/std/__iterator/iterator_traits.h +++ b/libcudacxx/include/cuda/std/__iterator/iterator_traits.h @@ -172,51 +172,55 @@ using _ITER_TRAITS = typename __iter_traits_cache<_Iter>::type; #if defined(_GLIBCXX_DEBUG) _CCCL_TEMPLATE(class _Iter, class _Ty, class _Range) -_CCCL_REQUIRES(same_as<_Iter, ::__gnu_debug::_Safe_iterator<_Ty*, _Range>>) -auto __iter_concept_fn(::__gnu_debug::_Safe_iterator<_Ty*, _Range>, __priority_tag<3>) -> contiguous_iterator_tag; +_CCCL_REQUIRES(_IsSame<_Iter, ::__gnu_debug::_Safe_iterator<_Ty*, _Range>>::value) +_LIBCUDACXX_HIDE_FROM_ABI auto + __iter_concept_fn(::__gnu_debug::_Safe_iterator<_Ty*, _Range>, __priority_tag<3>) -> contiguous_iterator_tag; #endif #if defined(__GLIBCXX__) _CCCL_TEMPLATE(class _Iter, class _Ty, class _Range) -_CCCL_REQUIRES(same_as<_Iter, ::__gnu_cxx::__normal_iterator<_Ty*, _Range>>) -auto __iter_concept_fn(::__gnu_cxx::__normal_iterator<_Ty*, _Range>, __priority_tag<3>) -> contiguous_iterator_tag; +_CCCL_REQUIRES(_IsSame<_Iter, ::__gnu_cxx::__normal_iterator<_Ty*, _Range>>::value) +_LIBCUDACXX_HIDE_FROM_ABI auto + __iter_concept_fn(::__gnu_cxx::__normal_iterator<_Ty*, _Range>, __priority_tag<3>) -> contiguous_iterator_tag; #endif #if defined(_LIBCPP_VERSION) _CCCL_TEMPLATE(class _Iter, class _Ty) -_CCCL_REQUIRES(same_as<_Iter, ::std::__wrap_iter<_Ty*>>) -auto __iter_concept_fn(::std::__wrap_iter<_Ty*>, __priority_tag<3>) -> contiguous_iterator_tag; +_CCCL_REQUIRES(_IsSame<_Iter, ::std::__wrap_iter<_Ty*>>::value) +_LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(::std::__wrap_iter<_Ty*>, __priority_tag<3>) -> contiguous_iterator_tag; #endif #if defined(_MSVC_STL_VERSION) || defined(_IS_WRS) _CCCL_TEMPLATE(class _Iter) -_CCCL_REQUIRES(same_as<_Iter, class _Iter::_Array_iterator>) -auto __iter_concept_fn(_Iter, __priority_tag<3>) -> contiguous_iterator_tag; +_CCCL_REQUIRES(_IsSame<_Iter, class _Iter::_Array_iterator>::value) +_LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(_Iter, __priority_tag<3>) -> contiguous_iterator_tag; _CCCL_TEMPLATE(class _Iter) -_CCCL_REQUIRES(same_as<_Iter, class _Iter::_Array_const_iterator>) -auto __iter_concept_fn(_Iter, __priority_tag<3>) -> contiguous_iterator_tag; +_CCCL_REQUIRES(_IsSame<_Iter, class _Iter::_Array_const_iterator>::value) +_LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(_Iter, __priority_tag<3>) -> contiguous_iterator_tag; _CCCL_TEMPLATE(class _Iter) -_CCCL_REQUIRES(same_as<_Iter, class _Iter::_Vector_iterator>) -auto __iter_concept_fn(_Iter, __priority_tag<3>) -> contiguous_iterator_tag; +_CCCL_REQUIRES(_IsSame<_Iter, class _Iter::_Vector_iterator>::value) +_LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(_Iter, __priority_tag<3>) -> contiguous_iterator_tag; _CCCL_TEMPLATE(class _Iter) -_CCCL_REQUIRES(same_as<_Iter, class _Iter::_Vector_const_iterator>) -auto __iter_concept_fn(_Iter, __priority_tag<3>) -> contiguous_iterator_tag; +_CCCL_REQUIRES(_IsSame<_Iter, class _Iter::_Vector_const_iterator>::value) +_LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(_Iter, __priority_tag<3>) -> contiguous_iterator_tag; _CCCL_TEMPLATE(class _Iter) -_CCCL_REQUIRES(same_as<_Iter, class _Iter::_String_iterator>) -auto __iter_concept_fn(_Iter, __priority_tag<3>) -> contiguous_iterator_tag; +_CCCL_REQUIRES(_IsSame<_Iter, class _Iter::_String_iterator>::value) +_LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(_Iter, __priority_tag<3>) -> contiguous_iterator_tag; _CCCL_TEMPLATE(class _Iter) -_CCCL_REQUIRES(same_as<_Iter, class _Iter::_String_const_iterator>) -auto __iter_concept_fn(_Iter, __priority_tag<3>) -> contiguous_iterator_tag; +_CCCL_REQUIRES(_IsSame<_Iter, class _Iter::_String_const_iterator>::value) +_LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(_Iter, __priority_tag<3>) -> contiguous_iterator_tag; _CCCL_TEMPLATE(class _Iter) -_CCCL_REQUIRES(same_as<_Iter, class _Iter::_String_view_iterator>) -auto __iter_concept_fn(_Iter, __priority_tag<3>) -> contiguous_iterator_tag; +_CCCL_REQUIRES(_IsSame<_Iter, class _Iter::_String_view_iterator>::value) +_LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(_Iter, __priority_tag<3>) -> contiguous_iterator_tag; #endif _CCCL_TEMPLATE(class _Iter, class _Ty) -_CCCL_REQUIRES(same_as<_Iter, _Ty*>) -auto __iter_concept_fn(_Ty*, __priority_tag<3>) -> contiguous_iterator_tag; +_CCCL_REQUIRES(_IsSame<_Iter, _Ty*>::value) +_LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(_Ty*, __priority_tag<3>) -> contiguous_iterator_tag; template -auto __iter_concept_fn(_Iter, __priority_tag<2>) -> class _ITER_TRAITS<_Iter>::iterator_concept; +_LIBCUDACXX_HIDE_FROM_ABI auto + __iter_concept_fn(_Iter, __priority_tag<2>) -> class _ITER_TRAITS<_Iter>::iterator_concept; template -auto __iter_concept_fn(_Iter, __priority_tag<1>) -> class _ITER_TRAITS<_Iter>::iterator_category; +_LIBCUDACXX_HIDE_FROM_ABI auto + __iter_concept_fn(_Iter, __priority_tag<1>) -> class _ITER_TRAITS<_Iter>::iterator_category; template -auto __iter_concept_fn(_Iter, __priority_tag<0>) +_LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(_Iter, __priority_tag<0>) -> enable_if_t<__is_primary_template>::value, random_access_iterator_tag>; template From 0bd73a25e44e64845930ff2ec297b672ef0259be Mon Sep 17 00:00:00 2001 From: Eric Niebler Date: Thu, 19 Dec 2024 13:24:33 -0800 Subject: [PATCH 3/8] review feedback, and no contiguous iterators in c++11 --- .../cuda/std/__iterator/iterator_traits.h | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/libcudacxx/include/cuda/std/__iterator/iterator_traits.h b/libcudacxx/include/cuda/std/__iterator/iterator_traits.h index bddf5ad563b..ebcdfda0196 100644 --- a/libcudacxx/include/cuda/std/__iterator/iterator_traits.h +++ b/libcudacxx/include/cuda/std/__iterator/iterator_traits.h @@ -170,24 +170,23 @@ struct __iter_traits_cache template using _ITER_TRAITS = typename __iter_traits_cache<_Iter>::type; -#if defined(_GLIBCXX_DEBUG) +#if _CCCL_STD_VER >= 2014 +# if defined(_GLIBCXX_DEBUG) _CCCL_TEMPLATE(class _Iter, class _Ty, class _Range) _CCCL_REQUIRES(_IsSame<_Iter, ::__gnu_debug::_Safe_iterator<_Ty*, _Range>>::value) _LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(::__gnu_debug::_Safe_iterator<_Ty*, _Range>, __priority_tag<3>) -> contiguous_iterator_tag; -#endif -#if defined(__GLIBCXX__) +# endif +# if defined(__GLIBCXX__) _CCCL_TEMPLATE(class _Iter, class _Ty, class _Range) _CCCL_REQUIRES(_IsSame<_Iter, ::__gnu_cxx::__normal_iterator<_Ty*, _Range>>::value) _LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(::__gnu_cxx::__normal_iterator<_Ty*, _Range>, __priority_tag<3>) -> contiguous_iterator_tag; -#endif -#if defined(_LIBCPP_VERSION) +# elif defined(_LIBCPP_VERSION) _CCCL_TEMPLATE(class _Iter, class _Ty) _CCCL_REQUIRES(_IsSame<_Iter, ::std::__wrap_iter<_Ty*>>::value) _LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(::std::__wrap_iter<_Ty*>, __priority_tag<3>) -> contiguous_iterator_tag; -#endif -#if defined(_MSVC_STL_VERSION) || defined(_IS_WRS) +# elif defined(_MSVC_STL_VERSION) || defined(_IS_WRS) _CCCL_TEMPLATE(class _Iter) _CCCL_REQUIRES(_IsSame<_Iter, class _Iter::_Array_iterator>::value) _LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(_Iter, __priority_tag<3>) -> contiguous_iterator_tag; @@ -209,10 +208,14 @@ _LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(_Iter, __priority_tag<3>) -> co _CCCL_TEMPLATE(class _Iter) _CCCL_REQUIRES(_IsSame<_Iter, class _Iter::_String_view_iterator>::value) _LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(_Iter, __priority_tag<3>) -> contiguous_iterator_tag; -#endif +_CCCL_TEMPLATE(class _Iter) +_CCCL_REQUIRES(_IsSame<_Iter, class _Iter::_Span_iterator>::value) +_LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(_Iter, __priority_tag<3>) -> contiguous_iterator_tag; +# endif _CCCL_TEMPLATE(class _Iter, class _Ty) _CCCL_REQUIRES(_IsSame<_Iter, _Ty*>::value) _LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(_Ty*, __priority_tag<3>) -> contiguous_iterator_tag; +#endif // _CCCL_STD_VER >= 2014 template _LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(_Iter, __priority_tag<2>) -> class _ITER_TRAITS<_Iter>::iterator_concept; From 1de5b546a5f4dd6dc9b30a0a13d5da0897fef48b Mon Sep 17 00:00:00 2001 From: Eric Niebler Date: Thu, 19 Dec 2024 14:09:24 -0800 Subject: [PATCH 4/8] avoid elaborated type specifier when looking for nested type aliases --- libcudacxx/include/cuda/std/__iterator/iterator_traits.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libcudacxx/include/cuda/std/__iterator/iterator_traits.h b/libcudacxx/include/cuda/std/__iterator/iterator_traits.h index ebcdfda0196..33280bc72c4 100644 --- a/libcudacxx/include/cuda/std/__iterator/iterator_traits.h +++ b/libcudacxx/include/cuda/std/__iterator/iterator_traits.h @@ -217,11 +217,11 @@ _CCCL_REQUIRES(_IsSame<_Iter, _Ty*>::value) _LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(_Ty*, __priority_tag<3>) -> contiguous_iterator_tag; #endif // _CCCL_STD_VER >= 2014 template -_LIBCUDACXX_HIDE_FROM_ABI auto - __iter_concept_fn(_Iter, __priority_tag<2>) -> class _ITER_TRAITS<_Iter>::iterator_concept; +_LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(_Iter, __priority_tag<2>) -> + typename _ITER_TRAITS<_Iter>::iterator_concept; template -_LIBCUDACXX_HIDE_FROM_ABI auto - __iter_concept_fn(_Iter, __priority_tag<1>) -> class _ITER_TRAITS<_Iter>::iterator_category; +_LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(_Iter, __priority_tag<1>) -> + typename _ITER_TRAITS<_Iter>::iterator_category; template _LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(_Iter, __priority_tag<0>) -> enable_if_t<__is_primary_template>::value, random_access_iterator_tag>; From 3d1d01b5883eedac8b1792074a178862c7f96659 Mon Sep 17 00:00:00 2001 From: Eric Niebler Date: Fri, 20 Dec 2024 12:23:35 -0800 Subject: [PATCH 5/8] review feedback --- .../cuda/std/__iterator/iterator_traits.h | 29 ++++--------------- 1 file changed, 5 insertions(+), 24 deletions(-) diff --git a/libcudacxx/include/cuda/std/__iterator/iterator_traits.h b/libcudacxx/include/cuda/std/__iterator/iterator_traits.h index 33280bc72c4..3b675bf2cf5 100644 --- a/libcudacxx/include/cuda/std/__iterator/iterator_traits.h +++ b/libcudacxx/include/cuda/std/__iterator/iterator_traits.h @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -182,36 +183,16 @@ _CCCL_TEMPLATE(class _Iter, class _Ty, class _Range) _CCCL_REQUIRES(_IsSame<_Iter, ::__gnu_cxx::__normal_iterator<_Ty*, _Range>>::value) _LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(::__gnu_cxx::__normal_iterator<_Ty*, _Range>, __priority_tag<3>) -> contiguous_iterator_tag; -# elif defined(_LIBCPP_VERSION) +# endif // __GLIBCXX__ +# if defined(_LIBCPP_VERSION) _CCCL_TEMPLATE(class _Iter, class _Ty) _CCCL_REQUIRES(_IsSame<_Iter, ::std::__wrap_iter<_Ty*>>::value) _LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(::std::__wrap_iter<_Ty*>, __priority_tag<3>) -> contiguous_iterator_tag; # elif defined(_MSVC_STL_VERSION) || defined(_IS_WRS) _CCCL_TEMPLATE(class _Iter) -_CCCL_REQUIRES(_IsSame<_Iter, class _Iter::_Array_iterator>::value) +_CCCL_REQUIRES((_CCCL_TRAIT(is_pointer, ::std::_Unwrapped_t<_Iter>))) _LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(_Iter, __priority_tag<3>) -> contiguous_iterator_tag; -_CCCL_TEMPLATE(class _Iter) -_CCCL_REQUIRES(_IsSame<_Iter, class _Iter::_Array_const_iterator>::value) -_LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(_Iter, __priority_tag<3>) -> contiguous_iterator_tag; -_CCCL_TEMPLATE(class _Iter) -_CCCL_REQUIRES(_IsSame<_Iter, class _Iter::_Vector_iterator>::value) -_LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(_Iter, __priority_tag<3>) -> contiguous_iterator_tag; -_CCCL_TEMPLATE(class _Iter) -_CCCL_REQUIRES(_IsSame<_Iter, class _Iter::_Vector_const_iterator>::value) -_LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(_Iter, __priority_tag<3>) -> contiguous_iterator_tag; -_CCCL_TEMPLATE(class _Iter) -_CCCL_REQUIRES(_IsSame<_Iter, class _Iter::_String_iterator>::value) -_LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(_Iter, __priority_tag<3>) -> contiguous_iterator_tag; -_CCCL_TEMPLATE(class _Iter) -_CCCL_REQUIRES(_IsSame<_Iter, class _Iter::_String_const_iterator>::value) -_LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(_Iter, __priority_tag<3>) -> contiguous_iterator_tag; -_CCCL_TEMPLATE(class _Iter) -_CCCL_REQUIRES(_IsSame<_Iter, class _Iter::_String_view_iterator>::value) -_LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(_Iter, __priority_tag<3>) -> contiguous_iterator_tag; -_CCCL_TEMPLATE(class _Iter) -_CCCL_REQUIRES(_IsSame<_Iter, class _Iter::_Span_iterator>::value) -_LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(_Iter, __priority_tag<3>) -> contiguous_iterator_tag; -# endif +# endif // _MSVC_STL_VERSION _CCCL_TEMPLATE(class _Iter, class _Ty) _CCCL_REQUIRES(_IsSame<_Iter, _Ty*>::value) _LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(_Ty*, __priority_tag<3>) -> contiguous_iterator_tag; From 2a36fb26dce4e953ecb761898db8ebef235d507d Mon Sep 17 00:00:00 2001 From: Eric Niebler Date: Fri, 20 Dec 2024 14:00:30 -0800 Subject: [PATCH 6/8] try to avoid spurious template instantiation during ADL --- .../cuda/std/__iterator/iterator_traits.h | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/libcudacxx/include/cuda/std/__iterator/iterator_traits.h b/libcudacxx/include/cuda/std/__iterator/iterator_traits.h index 3b675bf2cf5..1f49f954c64 100644 --- a/libcudacxx/include/cuda/std/__iterator/iterator_traits.h +++ b/libcudacxx/include/cuda/std/__iterator/iterator_traits.h @@ -175,40 +175,42 @@ using _ITER_TRAITS = typename __iter_traits_cache<_Iter>::type; # if defined(_GLIBCXX_DEBUG) _CCCL_TEMPLATE(class _Iter, class _Ty, class _Range) _CCCL_REQUIRES(_IsSame<_Iter, ::__gnu_debug::_Safe_iterator<_Ty*, _Range>>::value) -_LIBCUDACXX_HIDE_FROM_ABI auto - __iter_concept_fn(::__gnu_debug::_Safe_iterator<_Ty*, _Range>, __priority_tag<3>) -> contiguous_iterator_tag; +_LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(__undefined<::__gnu_debug::_Safe_iterator<_Ty*, _Range>>*, + __priority_tag<3>) -> contiguous_iterator_tag; # endif # if defined(__GLIBCXX__) _CCCL_TEMPLATE(class _Iter, class _Ty, class _Range) _CCCL_REQUIRES(_IsSame<_Iter, ::__gnu_cxx::__normal_iterator<_Ty*, _Range>>::value) -_LIBCUDACXX_HIDE_FROM_ABI auto - __iter_concept_fn(::__gnu_cxx::__normal_iterator<_Ty*, _Range>, __priority_tag<3>) -> contiguous_iterator_tag; +_LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(__undefined<::__gnu_cxx::__normal_iterator<_Ty*, _Range>>*, + __priority_tag<3>) -> contiguous_iterator_tag; # endif // __GLIBCXX__ # if defined(_LIBCPP_VERSION) _CCCL_TEMPLATE(class _Iter, class _Ty) _CCCL_REQUIRES(_IsSame<_Iter, ::std::__wrap_iter<_Ty*>>::value) -_LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(::std::__wrap_iter<_Ty*>, __priority_tag<3>) -> contiguous_iterator_tag; +_LIBCUDACXX_HIDE_FROM_ABI auto +__iter_concept_fn(__undefined<::std::__wrap_iter<_Ty*>>*, __priority_tag<3>) -> contiguous_iterator_tag; # elif defined(_MSVC_STL_VERSION) || defined(_IS_WRS) _CCCL_TEMPLATE(class _Iter) _CCCL_REQUIRES((_CCCL_TRAIT(is_pointer, ::std::_Unwrapped_t<_Iter>))) -_LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(_Iter, __priority_tag<3>) -> contiguous_iterator_tag; +_LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(__undefined<_Iter>*, __priority_tag<3>) -> contiguous_iterator_tag; # endif // _MSVC_STL_VERSION _CCCL_TEMPLATE(class _Iter, class _Ty) _CCCL_REQUIRES(_IsSame<_Iter, _Ty*>::value) -_LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(_Ty*, __priority_tag<3>) -> contiguous_iterator_tag; +_LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(__undefined<_Ty*>*, __priority_tag<3>) -> contiguous_iterator_tag; #endif // _CCCL_STD_VER >= 2014 template -_LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(_Iter, __priority_tag<2>) -> +_LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(__undefined<_Iter>*, __priority_tag<2>) -> typename _ITER_TRAITS<_Iter>::iterator_concept; template -_LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(_Iter, __priority_tag<1>) -> +_LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(__undefined<_Iter>*, __priority_tag<1>) -> typename _ITER_TRAITS<_Iter>::iterator_category; template -_LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(_Iter, __priority_tag<0>) +_LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(__undefined<_Iter>*, __priority_tag<0>) -> enable_if_t<__is_primary_template>::value, random_access_iterator_tag>; template -using __iter_concept_t = decltype(_CUDA_VSTD::__iter_concept_fn<_Iter>(declval<_Iter>(), __priority_tag<3>{})); +using __iter_concept_t = + decltype(_CUDA_VSTD::__iter_concept_fn<_Iter>(static_cast<__undefined<_Iter>*>(nullptr), __priority_tag<3>{})); template struct __iter_concept_cache From 67c075a9189e239b5b0f404207147b532bd5e465 Mon Sep 17 00:00:00 2001 From: Eric Niebler Date: Fri, 20 Dec 2024 14:01:36 -0800 Subject: [PATCH 7/8] remove needless parens --- libcudacxx/include/cuda/std/__iterator/iterator_traits.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libcudacxx/include/cuda/std/__iterator/iterator_traits.h b/libcudacxx/include/cuda/std/__iterator/iterator_traits.h index 1f49f954c64..c957e2dfbf0 100644 --- a/libcudacxx/include/cuda/std/__iterator/iterator_traits.h +++ b/libcudacxx/include/cuda/std/__iterator/iterator_traits.h @@ -191,7 +191,7 @@ _LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(__undefined<::std::__wrap_iter<_Ty*>>*, __priority_tag<3>) -> contiguous_iterator_tag; # elif defined(_MSVC_STL_VERSION) || defined(_IS_WRS) _CCCL_TEMPLATE(class _Iter) -_CCCL_REQUIRES((_CCCL_TRAIT(is_pointer, ::std::_Unwrapped_t<_Iter>))) +_CCCL_REQUIRES(_CCCL_TRAIT(is_pointer, ::std::_Unwrapped_t<_Iter>)) _LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(__undefined<_Iter>*, __priority_tag<3>) -> contiguous_iterator_tag; # endif // _MSVC_STL_VERSION _CCCL_TEMPLATE(class _Iter, class _Ty) From bde2fd4a16d19bd90ff439cdc44ee65add42de80 Mon Sep 17 00:00:00 2001 From: Eric Niebler Date: Fri, 20 Dec 2024 15:21:05 -0800 Subject: [PATCH 8/8] revert to a formulation that made msvc happy --- .../cuda/std/__iterator/iterator_traits.h | 47 +++++++++++++------ 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/libcudacxx/include/cuda/std/__iterator/iterator_traits.h b/libcudacxx/include/cuda/std/__iterator/iterator_traits.h index c957e2dfbf0..2168ea2fd5c 100644 --- a/libcudacxx/include/cuda/std/__iterator/iterator_traits.h +++ b/libcudacxx/include/cuda/std/__iterator/iterator_traits.h @@ -175,42 +175,61 @@ using _ITER_TRAITS = typename __iter_traits_cache<_Iter>::type; # if defined(_GLIBCXX_DEBUG) _CCCL_TEMPLATE(class _Iter, class _Ty, class _Range) _CCCL_REQUIRES(_IsSame<_Iter, ::__gnu_debug::_Safe_iterator<_Ty*, _Range>>::value) -_LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(__undefined<::__gnu_debug::_Safe_iterator<_Ty*, _Range>>*, - __priority_tag<3>) -> contiguous_iterator_tag; +_LIBCUDACXX_HIDE_FROM_ABI auto + __iter_concept_fn(::__gnu_debug::_Safe_iterator<_Ty*, _Range>, __priority_tag<3>) -> contiguous_iterator_tag; # endif # if defined(__GLIBCXX__) _CCCL_TEMPLATE(class _Iter, class _Ty, class _Range) _CCCL_REQUIRES(_IsSame<_Iter, ::__gnu_cxx::__normal_iterator<_Ty*, _Range>>::value) -_LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(__undefined<::__gnu_cxx::__normal_iterator<_Ty*, _Range>>*, - __priority_tag<3>) -> contiguous_iterator_tag; +_LIBCUDACXX_HIDE_FROM_ABI auto + __iter_concept_fn(::__gnu_cxx::__normal_iterator<_Ty*, _Range>, __priority_tag<3>) -> contiguous_iterator_tag; # endif // __GLIBCXX__ # if defined(_LIBCPP_VERSION) _CCCL_TEMPLATE(class _Iter, class _Ty) _CCCL_REQUIRES(_IsSame<_Iter, ::std::__wrap_iter<_Ty*>>::value) -_LIBCUDACXX_HIDE_FROM_ABI auto -__iter_concept_fn(__undefined<::std::__wrap_iter<_Ty*>>*, __priority_tag<3>) -> contiguous_iterator_tag; +_LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(::std::__wrap_iter<_Ty*>, __priority_tag<3>) -> contiguous_iterator_tag; # elif defined(_MSVC_STL_VERSION) || defined(_IS_WRS) _CCCL_TEMPLATE(class _Iter) -_CCCL_REQUIRES(_CCCL_TRAIT(is_pointer, ::std::_Unwrapped_t<_Iter>)) -_LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(__undefined<_Iter>*, __priority_tag<3>) -> contiguous_iterator_tag; +_CCCL_REQUIRES(_IsSame<_Iter, class _Iter::_Array_iterator>::value) +_LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(_Iter, __priority_tag<3>) -> contiguous_iterator_tag; +_CCCL_TEMPLATE(class _Iter) +_CCCL_REQUIRES(_IsSame<_Iter, class _Iter::_Array_const_iterator>::value) +_LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(_Iter, __priority_tag<3>) -> contiguous_iterator_tag; +_CCCL_TEMPLATE(class _Iter) +_CCCL_REQUIRES(_IsSame<_Iter, class _Iter::_Vector_iterator>::value) +_LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(_Iter, __priority_tag<3>) -> contiguous_iterator_tag; +_CCCL_TEMPLATE(class _Iter) +_CCCL_REQUIRES(_IsSame<_Iter, class _Iter::_Vector_const_iterator>::value) +_LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(_Iter, __priority_tag<3>) -> contiguous_iterator_tag; +_CCCL_TEMPLATE(class _Iter) +_CCCL_REQUIRES(_IsSame<_Iter, class _Iter::_String_iterator>::value) +_LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(_Iter, __priority_tag<3>) -> contiguous_iterator_tag; +_CCCL_TEMPLATE(class _Iter) +_CCCL_REQUIRES(_IsSame<_Iter, class _Iter::_String_const_iterator>::value) +_LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(_Iter, __priority_tag<3>) -> contiguous_iterator_tag; +_CCCL_TEMPLATE(class _Iter) +_CCCL_REQUIRES(_IsSame<_Iter, class _Iter::_String_view_iterator>::value) +_LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(_Iter, __priority_tag<3>) -> contiguous_iterator_tag; +_CCCL_TEMPLATE(class _Iter) +_CCCL_REQUIRES(_IsSame<_Iter, class _Iter::_Span_iterator>::value) +_LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(_Iter, __priority_tag<3>) -> contiguous_iterator_tag; # endif // _MSVC_STL_VERSION _CCCL_TEMPLATE(class _Iter, class _Ty) _CCCL_REQUIRES(_IsSame<_Iter, _Ty*>::value) -_LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(__undefined<_Ty*>*, __priority_tag<3>) -> contiguous_iterator_tag; +_LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(_Ty*, __priority_tag<3>) -> contiguous_iterator_tag; #endif // _CCCL_STD_VER >= 2014 template -_LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(__undefined<_Iter>*, __priority_tag<2>) -> +_LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(_Iter, __priority_tag<2>) -> typename _ITER_TRAITS<_Iter>::iterator_concept; template -_LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(__undefined<_Iter>*, __priority_tag<1>) -> +_LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(_Iter, __priority_tag<1>) -> typename _ITER_TRAITS<_Iter>::iterator_category; template -_LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(__undefined<_Iter>*, __priority_tag<0>) +_LIBCUDACXX_HIDE_FROM_ABI auto __iter_concept_fn(_Iter, __priority_tag<0>) -> enable_if_t<__is_primary_template>::value, random_access_iterator_tag>; template -using __iter_concept_t = - decltype(_CUDA_VSTD::__iter_concept_fn<_Iter>(static_cast<__undefined<_Iter>*>(nullptr), __priority_tag<3>{})); +using __iter_concept_t = decltype(_CUDA_VSTD::__iter_concept_fn<_Iter>(declval<_Iter>(), __priority_tag<3>{})); template struct __iter_concept_cache