Skip to content

Commit c6c032f

Browse files
authored
Improve handling of language level features (#3069)
* Cleanup out language detection machinery * Add global check for CTAD * Add global detection for threeway comparison
1 parent 05ab9cf commit c6c032f

File tree

13 files changed

+102
-72
lines changed

13 files changed

+102
-72
lines changed

cudax/include/cuda/experimental/__hierarchy/hierarchy_dimensions.cuh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -390,9 +390,9 @@ struct hierarchy_dimensions_fragment
390390
: levels(ls)
391391
{}
392392

393-
# if defined(__cpp_three_way_comparison) && __cpp_three_way_comparison >= 201907
393+
# if !defined(_CCCL_NO_THREE_WAY_COMPARISON)
394394
_CCCL_NODISCARD _CUDAX_API constexpr bool operator==(const hierarchy_dimensions_fragment&) const noexcept = default;
395-
# else
395+
# else // ^^^ !_CCCL_NO_THREE_WAY_COMPARISON ^^^ / vvv _CCCL_NO_THREE_WAY_COMPARISON vvv
396396
_CCCL_NODISCARD_FRIEND _CUDAX_API constexpr bool
397397
operator==(const hierarchy_dimensions_fragment& left, const hierarchy_dimensions_fragment& right) noexcept
398398
{
@@ -404,7 +404,7 @@ struct hierarchy_dimensions_fragment
404404
{
405405
return left.levels != right.levels;
406406
}
407-
# endif
407+
# endif // _CCCL_NO_THREE_WAY_COMPARISON
408408

409409
private:
410410
// This being static is a bit of a hack to make extents_type working without incomplete class member access

cudax/include/cuda/experimental/__hierarchy/level_dimensions.cuh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ struct level_dimensions
129129
_CCCL_HOST_DEVICE constexpr level_dimensions()
130130
: dims(){};
131131

132-
# if defined(__cpp_three_way_comparison) && __cpp_three_way_comparison >= 201907
132+
# if !defined(_CCCL_NO_THREE_WAY_COMPARISON)
133133
_CCCL_NODISCARD _CUDAX_API constexpr bool operator==(const level_dimensions&) const noexcept = default;
134-
# else
134+
# else // ^^^ !_CCCL_NO_THREE_WAY_COMPARISON ^^^ / vvv _CCCL_NO_THREE_WAY_COMPARISON vvv
135135
_CCCL_NODISCARD_FRIEND _CUDAX_API constexpr bool
136136
operator==(const level_dimensions& left, const level_dimensions& right) noexcept
137137
{
@@ -143,7 +143,7 @@ struct level_dimensions
143143
{
144144
return left.dims != right.dims;
145145
}
146-
# endif
146+
# endif // _CCCL_NO_THREE_WAY_COMPARISON
147147
};
148148

149149
/**

cudax/include/cuda/experimental/__utility/basic_any/basic_any_ptr.cuh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,13 @@ struct _CCCL_TYPE_VISIBILITY_DEFAULT basic_any<_Interface*>
177177
return *static_cast<_CUDA_VSTD::__maybe_const<__is_const_ptr, _Vp>**>(static_cast<void*>(&__ref_.__optr_));
178178
}
179179

180-
#if defined(__cpp_three_way_comparison)
180+
#if !defined(_CCCL_NO_THREE_WAY_COMPARISON)
181181
_CCCL_NODISCARD _CUDAX_HOST_API auto operator==(basic_any const& __other) const noexcept -> bool
182182
{
183183
using __void_ptr_t _CCCL_NODEBUG_ALIAS = _CUDA_VSTD::__maybe_const<__is_const_ptr, void>* const*;
184184
return *static_cast<__void_ptr_t>(__get_optr()) == *static_cast<__void_ptr_t>(__other.__get_optr());
185185
}
186-
#else // ^^^ __cpp_three_way_comparison ^^^ / vvv !__cpp_three_way_comparison vvv
186+
#else // ^^^ !_CCCL_NO_THREE_WAY_COMPARISON ^^^ / vvv _CCCL_NO_THREE_WAY_COMPARISON vvv
187187
_CCCL_NODISCARD_FRIEND _CUDAX_HOST_API auto operator==(basic_any const& __lhs, basic_any const& __rhs) noexcept -> bool
188188
{
189189
using __void_ptr_t _CCCL_NODEBUG_ALIAS = _CUDA_VSTD::__maybe_const<__is_const_ptr, void>* const*;
@@ -195,7 +195,7 @@ struct _CCCL_TYPE_VISIBILITY_DEFAULT basic_any<_Interface*>
195195
{
196196
return !(__lhs == __rhs);
197197
}
198-
#endif // !__cpp_three_way_comparison
198+
#endif // _CCCL_NO_THREE_WAY_COMPARISON
199199

200200
using __any_ref_t _CCCL_NODEBUG_ALIAS =
201201
_CUDA_VSTD::__maybe_const<__is_const_ptr, basic_any<__ireference<_Interface>>>;

cudax/include/cuda/experimental/__utility/basic_any/semiregular.cuh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,14 @@ struct iequality_comparable : interface<iequality_comparable>
152152
_CCCL_REQUIRES(_CUDA_VSTD::equality_comparable<_Tp>)
153153
using overrides _CCCL_NODEBUG_ALIAS = overrides_for<_Tp, _CUDAX_FNPTR_CONSTANT_WAR(&__equal_fn<_Tp>)>;
154154

155-
#if defined(__cpp_three_way_comparison)
155+
#if !defined(_CCCL_NO_THREE_WAY_COMPARISON)
156156
_CCCL_NODISCARD _CUDAX_HOST_API auto operator==(iequality_comparable const& __other) const -> bool
157157
{
158158
auto const& __other = __cudax::basic_any_from(__other);
159159
void const* __obj = __basic_any_access::__get_optr(__other);
160160
return __cudax::virtcall<&__equal_fn<iequality_comparable>>(this, __other.type(), __obj);
161161
}
162-
#else // ^^^ __cpp_three_way_comparison ^^^ / vvv !__cpp_three_way_comparison vvv
162+
#else // ^^^ !_CCCL_NO_THREE_WAY_COMPARISON ^^^ / vvv _CCCL_NO_THREE_WAY_COMPARISON vvv
163163
_CCCL_NODISCARD_FRIEND _CUDAX_HOST_API auto
164164
operator==(iequality_comparable const& __left, iequality_comparable const& __right) -> bool
165165
{
@@ -173,7 +173,7 @@ struct iequality_comparable : interface<iequality_comparable>
173173
{
174174
return !(__left == __right);
175175
}
176-
#endif // !__cpp_three_way_comparison
176+
#endif // _CCCL_NO_THREE_WAY_COMPARISON
177177
};
178178

179179
} // namespace cuda::experimental

cudax/include/cuda/experimental/__utility/basic_any/virtual_ptrs.cuh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ struct __base_vptr
5858
return __vptr_;
5959
}
6060

61-
#if defined(__cpp_three_way_comparison)
61+
#if !defined(_CCCL_NO_THREE_WAY_COMPARISON)
6262
bool operator==(__base_vptr const& __other) const noexcept = default;
63-
#else // ^^^ __cpp_three_way_comparison ^^^ / vvv !__cpp_three_way_comparison vvv
63+
#else // ^^^ !_CCCL_NO_THREE_WAY_COMPARISON ^^^ / vvv _CCCL_NO_THREE_WAY_COMPARISON vvv
6464
_CCCL_NODISCARD_FRIEND _CUDAX_HOST_API constexpr auto operator==(__base_vptr __lhs, __base_vptr __rhs) noexcept -> bool
6565
{
6666
return __lhs.__vptr_ == __rhs.__vptr_;
@@ -70,7 +70,7 @@ struct __base_vptr
7070
{
7171
return !(__lhs == __rhs);
7272
}
73-
#endif // !__cpp_three_way_comparison
73+
#endif // _CCCL_NO_THREE_WAY_COMPARISON
7474

7575
__rtti_base const* __vptr_{};
7676
};

libcudacxx/include/cuda/std/__cccl/dialect.h

Lines changed: 74 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
# pragma system_header
2323
#endif // no system header
2424

25+
///////////////////////////////////////////////////////////////////////////////
26+
// Determine the C++ standard dialect
27+
///////////////////////////////////////////////////////////////////////////////
2528
#if _CCCL_COMPILER(MSVC)
2629
# if _MSVC_LANG <= 201103L
2730
# define _CCCL_STD_VER 2011
@@ -52,6 +55,9 @@
5255
# endif
5356
#endif // !_CCCL_COMPILER(MSVC)
5457

58+
///////////////////////////////////////////////////////////////////////////////
59+
// Conditionally enable constexpr per standard dialect
60+
///////////////////////////////////////////////////////////////////////////////
5561
#if _CCCL_STD_VER >= 2014
5662
# define _CCCL_CONSTEXPR_CXX14 constexpr
5763
#else // ^^^ C++14 ^^^ / vvv C++11 vvv
@@ -76,54 +82,79 @@
7682
# define _CCCL_CONSTEXPR_CXX23
7783
#endif // _CCCL_STD_VER <= 2020
7884

79-
#if _CCCL_STD_VER >= 2017 && defined(__cpp_if_constexpr)
80-
# define _CCCL_IF_CONSTEXPR if constexpr
81-
#else // ^^^ C++17 ^^^ / vvv C++14 vvv
85+
///////////////////////////////////////////////////////////////////////////////
86+
// Detect whether we can use some language features based on standard dialect
87+
///////////////////////////////////////////////////////////////////////////////
88+
#if _CCCL_STD_VER <= 2014 || __cpp_if_constexpr < 201606L
8289
# define _CCCL_NO_IF_CONSTEXPR
83-
# define _CCCL_IF_CONSTEXPR if
84-
#endif // _CCCL_STD_VER <= 2014
90+
#endif // _CCCL_STD_VER <= 2014 || !defined(__cpp_if_constexpr)
8591

86-
// In nvcc prior to 11.3 global variables could not be marked constexpr
87-
#if _CCCL_CUDACC_BELOW(11, 3)
88-
# define _CCCL_CONSTEXPR_GLOBAL const
89-
#else // ^^^ _CCCL_CUDACC_BELOW(11, 3) ^^^ / vvv _CCCL_CUDACC_AT_LEAST(11, 3) vvv
90-
# define _CCCL_CONSTEXPR_GLOBAL constexpr
91-
#endif // _CCCL_CUDACC_AT_LEAST(11, 3)
92+
// concepts are only available from C++20 onwards
93+
#if _CCCL_STD_VER <= 2017 || __cpp_concepts < 201907L
94+
# define _CCCL_NO_CONCEPTS
95+
#endif // _CCCL_STD_VER <= 2017 || __cpp_concepts < 201907L
96+
97+
// CTAD is only available from C++17 onwards
98+
#if _CCCL_STD_VER <= 2014 || __cpp_deduction_guides < 201611L
99+
# define _CCCL_NO_DEDUCTION_GUIDES
100+
#endif // _CCCL_STD_VER <= 2014 || __cpp_deduction_guides < 201611L
101+
102+
// Fold expressions are only available from C++17 onwards
103+
#if _CCCL_STD_VER <= 2014 || __cpp_fold_expressions < 201603L
104+
# define _CCCL_NO_FOLD_EXPRESSIONS
105+
#endif // _CCCL_STD_VER <= 2014 || __cpp_fold_expressions < 201603L
92106

93107
// Inline variables are only available from C++17 onwards
94-
#if _CCCL_STD_VER >= 2017 && defined(__cpp_inline_variables) && (__cpp_inline_variables >= 201606L)
95-
# define _CCCL_INLINE_VAR inline
96-
#else // ^^^ C++17 ^^^ / vvv C++14 vvv
108+
#if _CCCL_STD_VER <= 2014 || __cpp_inline_variables < 201606L
97109
# define _CCCL_NO_INLINE_VARIABLES
98-
# define _CCCL_INLINE_VAR
99-
#endif // _CCCL_STD_VER <= 2014
110+
#endif // _CCCL_STD_VER <= 2014 || __cpp_inline_variables < 201606L
100111

101-
// Variable templates are only available from C++14 onwards and require some compiler support
102-
#if _CCCL_STD_VER <= 2011 || !defined(__cpp_variable_templates) || (__cpp_variable_templates < 201304L)
103-
# define _CCCL_NO_VARIABLE_TEMPLATES
104-
#endif // _CCCL_STD_VER <= 2011
112+
// noexcept function types are only available from C++17 onwards
113+
#if _CCCL_STD_VER <= 2014 || __cpp_noexcept_function_type < 201510L
114+
# define _CCCL_NO_NOEXCEPT_FUNCTION_TYPE
115+
#endif // _CCCL_STD_VER <= 2014 || __cpp_noexcept_function_type < 201510L
105116

106117
// Declaring a non-type template parameters with auto is only available from C++17 onwards
107-
#if _CCCL_STD_VER >= 2017 && defined(__cpp_nontype_template_parameter_auto) \
108-
&& (__cpp_nontype_template_parameter_auto >= 201606L)
109-
# define _CCCL_NTTP_AUTO auto
110-
#else // ^^^ C++17 ^^^ / vvv C++14 vvv
118+
#if _CCCL_STD_VER <= 2014 || __cpp_nontype_template_parameter_auto < 201606L
111119
# define _CCCL_NO_NONTYPE_TEMPLATE_PARAMETER_AUTO
112-
# define _CCCL_NTTP_AUTO unsigned long long int
113-
#endif // _CCCL_STD_VER <= 2014
120+
#endif // _CCCL_STD_VER <= 2014 || __cpp_nontype_template_parameter_auto < 201606L
114121

115-
// concepts are only available from C++20 onwards
116-
#if _CCCL_STD_VER <= 2017 || !defined(__cpp_concepts) || (__cpp_concepts < 201907L)
117-
# define _CCCL_NO_CONCEPTS
118-
#endif // _CCCL_STD_VER <= 2017 || !defined(__cpp_concepts) || (__cpp_concepts < 201907L)
122+
// Three way comparison is only available from C++20 onwards
123+
#if _CCCL_STD_VER <= 2017 || __cpp_three_way_comparison < 201907
124+
# define _CCCL_NO_THREE_WAY_COMPARISON
125+
#endif // _CCCL_STD_VER <= 2017 || __cpp_three_way_comparison < 201907
119126

120-
// noexcept function types are only available from C++17 onwards
121-
#if _CCCL_STD_VER >= 2017 && defined(__cpp_noexcept_function_type) && (__cpp_noexcept_function_type >= 201510L)
122-
# define _CCCL_FUNCTION_TYPE_NOEXCEPT noexcept
123-
#else // ^^^ C++17 ^^^ / vvv C++14 vvv
124-
# define _CCCL_NO_NOEXCEPT_FUNCTION_TYPE
127+
// Variable templates are only available from C++14 onwards and require some compiler support
128+
#if _CCCL_STD_VER <= 2011 || __cpp_variable_templates < 201304L
129+
# define _CCCL_NO_VARIABLE_TEMPLATES
130+
#endif // _CCCL_STD_VER <= 2011 || __cpp_variable_templates < 201304L
131+
132+
///////////////////////////////////////////////////////////////////////////////
133+
// Conditionally use certain language features depending on availablility
134+
///////////////////////////////////////////////////////////////////////////////
135+
#if defined(_CCCL_NO_IF_CONSTEXPR)
136+
# define _CCCL_IF_CONSTEXPR if
137+
#else // ^^^ _CCCL_NO_IF_CONSTEXPR ^^^ / vvv !_CCCL_NO_IF_CONSTEXPR vvv
138+
# define _CCCL_IF_CONSTEXPR if constexpr
139+
#endif // !_CCCL_NO_IF_CONSTEXPR
140+
141+
#if defined(_CCCL_NO_INLINE_VARIABLES)
142+
# define _CCCL_INLINE_VAR
143+
#else // ^^^ _CCCL_NO_INLINE_VARIABLES ^^^ / vvv !_CCCL_NO_INLINE_VARIABLES vvv
144+
# define _CCCL_INLINE_VAR inline
145+
#endif // !_CCCL_NO_INLINE_VARIABLES
146+
147+
#if defined(_CCCL_NO_NOEXCEPT_FUNCTION_TYPE)
125148
# define _CCCL_FUNCTION_TYPE_NOEXCEPT
126-
#endif // _CCCL_STD_VER <= 2014
149+
#else // ^^^ _CCCL_NO_NOEXCEPT_FUNCTION_TYPE ^^^ / vvv !_CCCL_NO_NOEXCEPT_FUNCTION_TYPE vvv
150+
# define _CCCL_FUNCTION_TYPE_NOEXCEPT noexcept
151+
#endif // !_CCCL_NO_NOEXCEPT_FUNCTION_TYPE
152+
153+
#if defined(_CCCL_NO_NONTYPE_TEMPLATE_PARAMETER_AUTO)
154+
# define _CCCL_NTTP_AUTO unsigned long long int
155+
#else // ^^^ _CCCL_NO_NONTYPE_TEMPLATE_PARAMETER_AUTO ^^^ / vvv !_CCCL_NO_NONTYPE_TEMPLATE_PARAMETER_AUTO vvv
156+
# define _CCCL_NTTP_AUTO auto
157+
#endif // !_CCCL_NO_NONTYPE_TEMPLATE_PARAMETER_AUTO
127158

128159
// Variable templates are more efficient most of the time, so we want to use them rather than structs when possible
129160
#if defined(_CCCL_NO_VARIABLE_TEMPLATES)
@@ -132,6 +163,13 @@
132163
# define _CCCL_TRAIT(__TRAIT, ...) __TRAIT##_v<__VA_ARGS__>
133164
#endif // !_CCCL_NO_VARIABLE_TEMPLATES
134165

166+
// In nvcc prior to 11.3 global variables could not be marked constexpr
167+
#if _CCCL_CUDACC_BELOW(11, 3)
168+
# define _CCCL_CONSTEXPR_GLOBAL const
169+
#else // ^^^ _CCCL_CUDACC_BELOW(11, 3) ^^^ / vvv _CCCL_CUDACC_AT_LEAST(11, 3) vvv
170+
# define _CCCL_CONSTEXPR_GLOBAL constexpr
171+
#endif // _CCCL_CUDACC_AT_LEAST(11, 3)
172+
135173
// We need to treat host and device separately
136174
#if defined(__CUDA_ARCH__)
137175
# define _CCCL_GLOBAL_CONSTANT _CCCL_DEVICE _CCCL_CONSTEXPR_GLOBAL

libcudacxx/include/cuda/std/__expected/unexpected.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,10 @@ class unexpected
161161
_Err __unex_;
162162
};
163163

164-
# if _CCCL_STD_VER > 2014 && !defined(_LIBCUDACXX_HAS_NO_DEDUCTION_GUIDES)
164+
# if !defined(_CCCL_NO_DEDUCTION_GUIDES)
165165
template <class _Err>
166166
unexpected(_Err) -> unexpected<_Err>;
167-
# endif // _CCCL_STD_VER > 2014 && !defined(_LIBCUDACXX_HAS_NO_DEDUCTION_GUIDES)
167+
# endif // !defined(_CCCL_NO_DEDUCTION_GUIDES)
168168

169169
#endif // _CCCL_STD_VER > 2011
170170

libcudacxx/include/cuda/std/__functional/reference_wrapper.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ class _CCCL_TYPE_VISIBILITY_DEFAULT reference_wrapper : public __weak_result_typ
7676
}
7777
};
7878

79-
#if _CCCL_STD_VER > 2014 && !defined(_LIBCUDACXX_HAS_NO_DEDUCTION_GUIDES)
79+
#if !defined(_CCCL_NO_DEDUCTION_GUIDES)
8080
template <class _Tp>
8181
_CCCL_HOST_DEVICE reference_wrapper(_Tp&) -> reference_wrapper<_Tp>;
82-
#endif
82+
#endif // !_CCCL_NO_DEDUCTION_GUIDES
8383

8484
template <class _Tp>
8585
_LIBCUDACXX_HIDE_FROM_ABI _CCCL_CONSTEXPR_CXX20 reference_wrapper<_Tp> ref(_Tp& __t) noexcept

libcudacxx/include/cuda/std/__type_traits/fold.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
_LIBCUDACXX_BEGIN_NAMESPACE_STD
2828

29-
#if !defined(_LIBCUDACXX_HAS_NO_FOLD_EXPRESSIONS)
29+
#if !defined(_CCCL_NO_FOLD_EXPRESSIONS)
3030

3131
// Use fold expressions when possible to implement __fold_and[_v] and
3232
// __fold_or[_v].
@@ -42,7 +42,7 @@ using __fold_and = bool_constant<bool((_Preds && ...))>; // cast to bool to avoi
4242
template <bool... _Preds>
4343
using __fold_or = bool_constant<bool((_Preds || ...))>; // cast to bool to avoid error from gcc < 8
4444

45-
#else // ^^^ !_LIBCUDACXX_HAS_NO_FOLD_EXPRESSIONS / _LIBCUDACXX_HAS_NO_FOLD_EXPRESSIONS vvv
45+
#else // ^^^ !_CCCL_NO_FOLD_EXPRESSIONS / _CCCL_NO_FOLD_EXPRESSIONS vvv
4646

4747
// Otherwise, we can use a helper class to implement __fold_and and __fold_or.
4848
template <bool... _Preds>
@@ -62,7 +62,7 @@ template <bool... _Preds>
6262
_CCCL_INLINE_VAR constexpr bool __fold_or_v = __fold_or<_Preds...>::value;
6363
# endif // !_CCCL_NO_VARIABLE_TEMPLATES
6464

65-
#endif // _LIBCUDACXX_HAS_NO_FOLD_EXPRESSIONS
65+
#endif // _CCCL_NO_FOLD_EXPRESSIONS
6666

6767
_LIBCUDACXX_END_NAMESPACE_STD
6868

libcudacxx/include/cuda/std/__utility/pair.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,10 +525,10 @@ struct _CCCL_TYPE_VISIBILITY_DEFAULT pair : public __pair_base<_T1, _T2>
525525
#endif // !_CCCL_COMPILER(NVRTC)
526526
};
527527

528-
#if _CCCL_STD_VER > 2014 && !defined(_LIBCUDACXX_HAS_NO_DEDUCTION_GUIDES)
528+
#if !defined(_CCCL_NO_DEDUCTION_GUIDES)
529529
template <class _T1, class _T2>
530530
_CCCL_HOST_DEVICE pair(_T1, _T2) -> pair<_T1, _T2>;
531-
#endif // _CCCL_STD_VER > 2014 && !defined(_LIBCUDACXX_HAS_NO_DEDUCTION_GUIDES)
531+
#endif // !_CCCL_NO_DEDUCTION_GUIDES
532532

533533
// [pairs.spec], specialized algorithms
534534

0 commit comments

Comments
 (0)