Skip to content

Commit

Permalink
Work around codegen issue with delegated constructors
Browse files Browse the repository at this point in the history
nvcc 11.1 has at times issues with delegated constructors of the form `using __base::__base`

It interprets the declaration as a type rather than a constructor, which breaks the world.

Work around it with yet another macro, that uses a slightly different spelling of the same thing
  • Loading branch information
miscco committed Jun 26, 2023
1 parent 38f2d1a commit 6c9a3d3
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 284 deletions.
16 changes: 16 additions & 0 deletions libcudacxx/include/cuda/std/detail/libcxx/include/__config
Original file line number Diff line number Diff line change
Expand Up @@ -2199,6 +2199,22 @@ extern "C" _LIBCUDACXX_FUNC_VIS void __sanitizer_annotate_contiguous_container(
#endif // NVRTC || NVHPC-cuda || clang-cuda
#endif // !_LIBCUDACXX_DISABLE_EXEC_CHECK

// nvbug3961621
#if defined(_LIBCUDACXX_COMPILER_NVRTC) \
|| (defined(_LIBCUDACXX_COMPILER_NVCC) && _LIBCUDACXX_CUDACC_VER < 1102000)
#define _LIBCUDACXX_DELEGATE_CONSTRUCTORS(_CLASS, _BASE, ...) \
using __base = _BASE<__VA_ARGS__>; \
template<class... _Args> \
_LIBCUDACXX_INLINE_VISIBILITY constexpr \
_CLASS(_Args&&... __args) noexcept(noexcept(__base(_CUDA_VSTD::declval<_Args>()...))) \
: __base(_CUDA_VSTD::forward<_Args>(__args)...) \
{}
#else // ^^^ _LIBCUDACXX_COMPILER_NVRTC ^^^ / vvv !_LIBCUDACXX_COMPILER_NVRTC vvv
#define _LIBCUDACXX_DELEGATE_CONSTRUCTORS(_CLASS, _BASE, ...) \
using __base = _BASE<__VA_ARGS__>; \
using __base::__base;
#endif // !_LIBCUDACXX_COMPILER_NVRTC

#endif // __cplusplus

#endif // _LIBCUDACXX_CONFIG
Original file line number Diff line number Diff line change
Expand Up @@ -363,20 +363,10 @@ struct __expected_destruct<_Tp, _Err, true, true> {
template <class _Tp, class _Err>
struct __expected_storage : __expected_destruct<_Tp, _Err>
{
using __base = __expected_destruct<_Tp, _Err>;
_LIBCUDACXX_DELEGATE_CONSTRUCTORS(__expected_storage, __expected_destruct, _Tp, _Err);

#if defined(_LIBCUDACXX_COMPILER_NVRTC) // nvbug3961621
constexpr __expected_storage() noexcept = default;

template<class... _Args>
_LIBCUDACXX_INLINE_VISIBILITY constexpr
__expected_storage(_Args&&... __args) noexcept(noexcept(__base(_CUDA_VSTD::declval<_Args>()...)))
: __base(_CUDA_VSTD::forward<_Args>(__args)...)
{}
#else // ^^^ _LIBCUDACXX_COMPILER_NVRTC ^^^ / vvv !_LIBCUDACXX_COMPILER_NVRTC vvv
using __base::__base;
#endif // !_LIBCUDACXX_COMPILER_NVRTC

_LIBCUDACXX_TEMPLATE(class _T1, class _T2, class... _Args)
(requires _LIBCUDACXX_TRAIT(is_nothrow_constructible, _T1, _Args...))
static _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17
Expand Down Expand Up @@ -456,36 +446,16 @@ template <class _Tp, class _Err, bool =
_LIBCUDACXX_TRAIT(is_trivially_copy_constructible, _Err)>
struct __expected_copy : __expected_storage<_Tp, _Err>
{
using __base = __expected_storage<_Tp, _Err>;
#if defined(_LIBCUDACXX_COMPILER_NVRTC) // nvbug3961621
_LIBCUDACXX_DELEGATE_CONSTRUCTORS(__expected_copy, __expected_storage, _Tp, _Err);
constexpr __expected_copy() noexcept = default;

template<class... _Args>
_LIBCUDACXX_INLINE_VISIBILITY constexpr
__expected_copy(_Args&&... __args) noexcept(noexcept(__base(_CUDA_VSTD::declval<_Args>()...)))
: __base(_CUDA_VSTD::forward<_Args>(__args)...)
{}
#else // ^^^ _LIBCUDACXX_COMPILER_NVRTC ^^^ / vvv !_LIBCUDACXX_COMPILER_NVRTC vvv
using __base::__base;
#endif // !_LIBCUDACXX_COMPILER_NVRTC
};

template <class _Tp, class _Err>
struct __expected_copy<_Tp, _Err, false> : __expected_storage<_Tp, _Err>
{
using __base = __expected_storage<_Tp, _Err>;
_LIBCUDACXX_DELEGATE_CONSTRUCTORS(__expected_copy, __expected_storage, _Tp, _Err);

#if defined(_LIBCUDACXX_COMPILER_NVRTC) // nvbug3961621
template<class... _Args>
_LIBCUDACXX_INLINE_VISIBILITY constexpr
__expected_copy(_Args&&... __args) noexcept(noexcept(__base(_CUDA_VSTD::declval<_Args>()...)))
: __base(_CUDA_VSTD::forward<_Args>(__args)...)
{}
#else // ^^^ _LIBCUDACXX_COMPILER_NVRTC ^^^ / vvv !_LIBCUDACXX_COMPILER_NVRTC vvv
using __base::__base;
#endif // !_LIBCUDACXX_COMPILER_NVRTC

__expected_copy() noexcept = default;
constexpr __expected_copy() noexcept = default;

_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17
__expected_copy(const __expected_copy& __other)
Expand All @@ -510,35 +480,17 @@ template <class _Tp, class _Err, bool =
_LIBCUDACXX_TRAIT(is_trivially_move_constructible, _Err)>
struct __expected_move : __expected_copy<_Tp, _Err>
{
using __base = __expected_copy<_Tp, _Err>;
#if defined(_LIBCUDACXX_COMPILER_NVRTC) // nvbug3961621
_LIBCUDACXX_DELEGATE_CONSTRUCTORS(__expected_move, __expected_copy, _Tp, _Err);
constexpr __expected_move() noexcept = default;

template<class... _Args>
_LIBCUDACXX_INLINE_VISIBILITY constexpr
__expected_move(_Args&&... __args) noexcept(noexcept(__base(_CUDA_VSTD::declval<_Args>()...)))
: __base(_CUDA_VSTD::forward<_Args>(__args)...)
{}
#else // ^^^ _LIBCUDACXX_COMPILER_NVRTC ^^^ / vvv !_LIBCUDACXX_COMPILER_NVRTC vvv
using __base::__base;
#endif // !_LIBCUDACXX_COMPILER_NVRTC
};

template <class _Tp, class _Err>
struct __expected_move<_Tp, _Err, false> : __expected_copy<_Tp, _Err>
{
using __base = __expected_copy<_Tp, _Err>;
#if defined(_LIBCUDACXX_COMPILER_NVRTC) // nvbug3961621
template<class... _Args>
_LIBCUDACXX_INLINE_VISIBILITY constexpr
__expected_move(_Args&&... __args) noexcept(noexcept(__base(_CUDA_VSTD::declval<_Args>()...)))
: __base(_CUDA_VSTD::forward<_Args>(__args)...)
{}
#else // ^^^ _LIBCUDACXX_COMPILER_NVRTC ^^^ / vvv !_LIBCUDACXX_COMPILER_NVRTC vvv
using __base::__base;
#endif // !_LIBCUDACXX_COMPILER_NVRTC
_LIBCUDACXX_DELEGATE_CONSTRUCTORS(__expected_move, __expected_copy, _Tp, _Err);

constexpr __expected_move() noexcept = default;

__expected_move() = default;
__expected_move(const __expected_move&) = default;

_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17
Expand Down Expand Up @@ -567,35 +519,17 @@ template <class _Tp, class _Err, bool =
_LIBCUDACXX_TRAIT(is_trivially_copy_assignable, _Err)>
struct __expected_copy_assign : __expected_move<_Tp, _Err>
{
using __base = __expected_move<_Tp, _Err>;
#if defined(_LIBCUDACXX_COMPILER_NVRTC) // nvbug3961621
_LIBCUDACXX_DELEGATE_CONSTRUCTORS(__expected_copy_assign, __expected_move, _Tp, _Err);
constexpr __expected_copy_assign() noexcept = default;

template<class... _Args>
_LIBCUDACXX_INLINE_VISIBILITY constexpr
__expected_copy_assign(_Args&&... __args) noexcept(noexcept(__base(_CUDA_VSTD::declval<_Args>()...)))
: __base(_CUDA_VSTD::forward<_Args>(__args)...)
{}
#else // ^^^ _LIBCUDACXX_COMPILER_NVRTC ^^^ / vvv !_LIBCUDACXX_COMPILER_NVRTC vvv
using __base::__base;
#endif // !_LIBCUDACXX_COMPILER_NVRTC
};

template <class _Tp, class _Err>
struct __expected_copy_assign<_Tp, _Err, false> : __expected_move<_Tp, _Err>
{
using __base = __expected_move<_Tp, _Err>;
#if defined(_LIBCUDACXX_COMPILER_NVRTC) // nvbug3961621
template<class... _Args>
_LIBCUDACXX_INLINE_VISIBILITY constexpr
__expected_copy_assign(_Args&&... __args) noexcept(noexcept(__base(_CUDA_VSTD::declval<_Args>()...)))
: __base(_CUDA_VSTD::forward<_Args>(__args)...)
{}
#else // ^^^ _LIBCUDACXX_COMPILER_NVRTC ^^^ / vvv !_LIBCUDACXX_COMPILER_NVRTC vvv
using __base::__base;
#endif // !_LIBCUDACXX_COMPILER_NVRTC
_LIBCUDACXX_DELEGATE_CONSTRUCTORS(__expected_copy_assign, __expected_move, _Tp, _Err);

constexpr __expected_copy_assign() noexcept = default;

__expected_copy_assign() = default;
__expected_copy_assign(const __expected_copy_assign&) = default;
__expected_copy_assign(__expected_copy_assign&&) = default;

Expand Down Expand Up @@ -632,35 +566,17 @@ template <class _Tp, class _Err, bool =
_LIBCUDACXX_TRAIT(is_trivially_move_assignable, _Err)>
struct __expected_move_assign : __expected_copy_assign<_Tp, _Err>
{
using __base = __expected_copy_assign<_Tp, _Err>;
#if defined(_LIBCUDACXX_COMPILER_NVRTC) // nvbug3961621
_LIBCUDACXX_DELEGATE_CONSTRUCTORS(__expected_move_assign, __expected_copy_assign, _Tp, _Err);
constexpr __expected_move_assign() noexcept = default;

template<class... _Args>
_LIBCUDACXX_INLINE_VISIBILITY constexpr
__expected_move_assign(_Args&&... __args) noexcept(noexcept(__base(_CUDA_VSTD::declval<_Args>()...)))
: __base(_CUDA_VSTD::forward<_Args>(__args)...)
{}
#else // ^^^ _LIBCUDACXX_COMPILER_NVRTC ^^^ / vvv !_LIBCUDACXX_COMPILER_NVRTC vvv
using __base::__base;
#endif // !_LIBCUDACXX_COMPILER_NVRTC
};

template <class _Tp, class _Err>
struct __expected_move_assign<_Tp, _Err, false> : __expected_copy_assign<_Tp, _Err>
{
using __base = __expected_copy_assign<_Tp, _Err>;
#if defined(_LIBCUDACXX_COMPILER_NVRTC) // nvbug3961621
template<class... _Args>
_LIBCUDACXX_INLINE_VISIBILITY constexpr
__expected_move_assign(_Args&&... __args) noexcept(noexcept(__base(_CUDA_VSTD::declval<_Args>()...)))
: __base(_CUDA_VSTD::forward<_Args>(__args)...)
{}
#else // ^^^ _LIBCUDACXX_COMPILER_NVRTC ^^^ / vvv !_LIBCUDACXX_COMPILER_NVRTC vvv
using __base::__base;
#endif // !_LIBCUDACXX_COMPILER_NVRTC
_LIBCUDACXX_DELEGATE_CONSTRUCTORS(__expected_move_assign, __expected_copy_assign, _Tp, _Err);

constexpr __expected_move_assign() noexcept = default;

__expected_move_assign() = default;
__expected_move_assign(const __expected_move_assign&) = default;
__expected_move_assign(__expected_move_assign&&) = default;
__expected_move_assign& operator=(const __expected_move_assign&) = default;
Expand Down Expand Up @@ -831,18 +747,9 @@ struct __expected_destruct<void, _Err, false, true> {
template <class _Err>
struct __expected_storage<void, _Err> : __expected_destruct<void, _Err>
{
using __base = __expected_destruct<void, _Err>;
#if defined(_LIBCUDACXX_COMPILER_NVRTC) // nvbug3961621
constexpr __expected_storage() noexcept = default;
_LIBCUDACXX_DELEGATE_CONSTRUCTORS(__expected_storage, __expected_destruct, void, _Err);

template<class... _Args>
_LIBCUDACXX_INLINE_VISIBILITY constexpr
__expected_storage(_Args&&... __args) noexcept(noexcept(__base(_CUDA_VSTD::declval<_Args>()...)))
: __base(_CUDA_VSTD::forward<_Args>(__args)...)
{}
#else // ^^^ _LIBCUDACXX_COMPILER_NVRTC ^^^ / vvv !_LIBCUDACXX_COMPILER_NVRTC vvv
using __base::__base;
#endif // !_LIBCUDACXX_COMPILER_NVRTC
constexpr __expected_storage() noexcept = default;

static _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17
void __swap_val_unex_impl(__expected_storage& __with_val, __expected_storage& __with_err)
Expand All @@ -857,18 +764,9 @@ struct __expected_storage<void, _Err> : __expected_destruct<void, _Err>
template <class _Err>
struct __expected_copy<void, _Err, false> : __expected_storage<void, _Err>
{
using __base = __expected_storage<void, _Err>;
#if defined(_LIBCUDACXX_COMPILER_NVRTC) // nvbug3961621
template<class... _Args>
_LIBCUDACXX_INLINE_VISIBILITY constexpr
__expected_copy(_Args&&... __args) noexcept(noexcept(__base(_CUDA_VSTD::declval<_Args>()...)))
: __base(_CUDA_VSTD::forward<_Args>(__args)...)
{}
#else // ^^^ _LIBCUDACXX_COMPILER_NVRTC ^^^ / vvv !_LIBCUDACXX_COMPILER_NVRTC vvv
using __base::__base;
#endif // !_LIBCUDACXX_COMPILER_NVRTC
_LIBCUDACXX_DELEGATE_CONSTRUCTORS(__expected_copy, __expected_storage, void, _Err);

constexpr __expected_copy() = default;
constexpr __expected_copy() noexcept = default;

_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17
__expected_copy(const __expected_copy& __other)
Expand All @@ -888,18 +786,10 @@ struct __expected_copy<void, _Err, false> : __expected_storage<void, _Err>
template <class _Err>
struct __expected_move<void, _Err, false> : __expected_copy<void, _Err>
{
using __base = __expected_copy<void, _Err>;
#if defined(_LIBCUDACXX_COMPILER_NVRTC) // nvbug3961621
template<class... _Args>
_LIBCUDACXX_INLINE_VISIBILITY constexpr
__expected_move(_Args&&... __args) noexcept(noexcept(__base(_CUDA_VSTD::declval<_Args>()...)))
: __base(_CUDA_VSTD::forward<_Args>(__args)...)
{}
#else // ^^^ _LIBCUDACXX_COMPILER_NVRTC ^^^ / vvv !_LIBCUDACXX_COMPILER_NVRTC vvv
using __base::__base;
#endif // !_LIBCUDACXX_COMPILER_NVRTC
_LIBCUDACXX_DELEGATE_CONSTRUCTORS(__expected_move, __expected_copy, void, _Err);

constexpr __expected_move() noexcept = default;

__expected_move() = default;
__expected_move(const __expected_move&) = default;

_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17
Expand All @@ -919,18 +809,10 @@ struct __expected_move<void, _Err, false> : __expected_copy<void, _Err>
template <class _Err>
struct __expected_copy_assign<void, _Err, false> : __expected_move<void, _Err>
{
using __base = __expected_move<void, _Err>;
#if defined(_LIBCUDACXX_COMPILER_NVRTC) // nvbug3961621
template<class... _Args>
_LIBCUDACXX_INLINE_VISIBILITY constexpr
__expected_copy_assign(_Args&&... __args) noexcept(noexcept(__base(_CUDA_VSTD::declval<_Args>()...)))
: __base(_CUDA_VSTD::forward<_Args>(__args)...)
{}
#else // ^^^ _LIBCUDACXX_COMPILER_NVRTC ^^^ / vvv !_LIBCUDACXX_COMPILER_NVRTC vvv
using __base::__base;
#endif // !_LIBCUDACXX_COMPILER_NVRTC
_LIBCUDACXX_DELEGATE_CONSTRUCTORS(__expected_copy_assign, __expected_move, void, _Err);

constexpr __expected_copy_assign() noexcept = default;

__expected_copy_assign() = default;
__expected_copy_assign(const __expected_copy_assign&) = default;
__expected_copy_assign(__expected_copy_assign&&) = default;

Expand Down Expand Up @@ -959,18 +841,10 @@ struct __expected_copy_assign<void, _Err, false> : __expected_move<void, _Err>
template <class _Err>
struct __expected_move_assign<void, _Err, false> : __expected_copy_assign<void, _Err>
{
using __base = __expected_copy_assign<void, _Err>;
#if defined(_LIBCUDACXX_COMPILER_NVRTC) // nvbug3961621
template<class... _Args>
_LIBCUDACXX_INLINE_VISIBILITY constexpr
__expected_move_assign(_Args&&... __args) noexcept(noexcept(__base(_CUDA_VSTD::declval<_Args>()...)))
: __base(_CUDA_VSTD::forward<_Args>(__args)...)
{}
#else // ^^^ _LIBCUDACXX_COMPILER_NVRTC ^^^ / vvv !_LIBCUDACXX_COMPILER_NVRTC vvv
using __base::__base;
#endif // !_LIBCUDACXX_COMPILER_NVRTC
_LIBCUDACXX_DELEGATE_CONSTRUCTORS(__expected_move_assign, __expected_copy_assign, void, _Err);

constexpr __expected_move_assign() noexcept = default;

__expected_move_assign() = default;
__expected_move_assign(const __expected_move_assign&) = default;
__expected_move_assign(__expected_move_assign&&) = default;
__expected_move_assign& operator=(const __expected_move_assign&) = default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,7 @@ struct __bind_front_op {

template <class _Fn, class ..._BoundArgs>
struct __bind_front_t : __perfect_forward<__bind_front_op, _Fn, _BoundArgs...> {
using __base = __perfect_forward<__bind_front_op, _Fn, _BoundArgs...>;
#if defined(_LIBCUDACXX_COMPILER_NVRTC)
constexpr __bind_front_t() noexcept = default;

template<class... _Args>
_LIBCUDACXX_INLINE_VISIBILITY constexpr
__bind_front_t(_Args&&... __args) noexcept(noexcept(__base(_CUDA_VSTD::declval<_Args>()...)))
: __base(_CUDA_VSTD::forward<_Args>(__args)...)
{}
#else
using __base::__base;
#endif
_LIBCUDACXX_DELEGATE_CONSTRUCTORS(__bind_front_t, __perfect_forward, __bind_front_op, _Fn, _BoundArgs...);
};

template<class _Fn, class... _Args>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,7 @@ struct __not_fn_op {

template <class _Fn>
struct __not_fn_t : __perfect_forward<__not_fn_op, _Fn> {
using __base = __perfect_forward<__not_fn_op, _Fn>;
#if defined(_LIBCUDACXX_COMPILER_NVRTC) // nvbug 3961621
constexpr __not_fn_t() noexcept = default;

_LIBCUDACXX_TEMPLATE(class _OrigFn)
(requires _LIBCUDACXX_TRAIT(is_same, _Fn, __decay_t<_OrigFn>))
_LIBCUDACXX_INLINE_VISIBILITY constexpr
__not_fn_t(_OrigFn&& __fn) noexcept(noexcept(__base(_CUDA_VSTD::declval<_OrigFn>())))
: __base(_CUDA_VSTD::forward<_OrigFn>(__fn))
{}
#else
using __base::__base;
#endif
_LIBCUDACXX_DELEGATE_CONSTRUCTORS(__not_fn_t, __perfect_forward, __not_fn_op, _Fn);
};

template <class _Fn, class = enable_if_t<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ struct __partially_static_sizes_tagged
using __tag_t = _Tag;
using __psa_impl_t = __standard_layout_psa<
_Tag, T, _static_t, _CUDA_VSTD::integer_sequence<_static_t, __values_or_sentinals...>>;
using __psa_impl_t::__psa_impl_t;
_LIBCUDACXX_DELEGATE_CONSTRUCTORS(__partially_static_sizes_tagged, __standard_layout_psa, _Tag, T, _static_t, _CUDA_VSTD::integer_sequence<_static_t, __values_or_sentinals...>);
#ifdef __MDSPAN_DEFAULTED_CONSTRUCTORS_INHERITANCE_WORKAROUND
__MDSPAN_INLINE_FUNCTION
#endif
Expand Down Expand Up @@ -657,7 +657,7 @@ struct __partially_static_sizes
__partially_static_sizes_tagged<_UTag, T, _static_t, __values_or_sentinals...>&& __vals
) noexcept : __base_t(_CUDA_VSTD::move(__vals)) { }
public:
using __base_t::__base_t;
_LIBCUDACXX_DELEGATE_CONSTRUCTORS(__partially_static_sizes, __partially_static_sizes_tagged, __no_tag, T, _static_t, __values_or_sentinals...);

#ifdef __MDSPAN_DEFAULTED_CONSTRUCTORS_INHERITANCE_WORKAROUND
__MDSPAN_INLINE_FUNCTION
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,8 @@ template <class _Tp, class _static_t, class _ValsSeq, _static_t __sentinal = dyn
class __partially_static_array_with_sentinal
: public __partially_static_array_impl_maker<_Tp, _static_t, _ValsSeq, __sentinal>::__impl_base
{
private:
using __base_t = typename __partially_static_array_impl_maker<_Tp, _static_t, _ValsSeq, __sentinal>::__impl_base;
public:
using __base_t::__base_t;
_LIBCUDACXX_DELEGATE_CONSTRUCTORS(__partially_static_array_with_sentinal, __base_t);
};

//==============================================================================
Expand All @@ -272,11 +270,10 @@ struct __partially_static_sizes :
__partially_static_array_with_sentinal<
T, _static_t, _CUDA_VSTD::integer_sequence<_static_t, __values_or_sentinals...>>
{
private:
using __base_t = __partially_static_array_with_sentinal<
T, _static_t, _CUDA_VSTD::integer_sequence<_static_t, __values_or_sentinals...>>;
public:
using __base_t::__base_t;
_LIBCUDACXX_DELEGATE_CONSTRUCTORS(__partially_static_sizes, __base_t);

template <class _UTag>
__MDSPAN_FORCE_INLINE_FUNCTION constexpr __partially_static_sizes<T, _static_t, __values_or_sentinals...>
__with_tag() const noexcept {
Expand Down
Loading

0 comments on commit 6c9a3d3

Please sign in to comment.