Skip to content

Commit

Permalink
Suppress execution checks for vocabulary types (#3578)
Browse files Browse the repository at this point in the history
* Suppress execution checks for optional
* Suppress execution checks for `expected`
* Suppress execution checks for `pair`
* Suppress execution checks for `variant`
  • Loading branch information
miscco authored Jan 30, 2025
1 parent a654bc6 commit b6209e8
Show file tree
Hide file tree
Showing 30 changed files with 1,714 additions and 10 deletions.
21 changes: 12 additions & 9 deletions libcudacxx/include/cuda/std/__expected/bad_expected_access.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,6 @@ class bad_expected_access;
template <>
class bad_expected_access<void> : public ::std::exception
{
protected:
_CCCL_HIDE_FROM_ABI bad_expected_access() noexcept = default;
_CCCL_HIDE_FROM_ABI bad_expected_access(const bad_expected_access&) = default;
_CCCL_HIDE_FROM_ABI bad_expected_access(bad_expected_access&&) = default;
_CCCL_HIDE_FROM_ABI bad_expected_access& operator=(const bad_expected_access&) = default;
_CCCL_HIDE_FROM_ABI bad_expected_access& operator=(bad_expected_access&&) = default;
~bad_expected_access() noexcept override = default;

public:
// The way this has been designed (by using a class template below) means that we'll already
// have a profusion of these vtables in TUs, and the dynamic linker will already have a bunch
Expand All @@ -74,10 +66,21 @@ template <class _Err>
class bad_expected_access : public bad_expected_access<void>
{
public:
explicit bad_expected_access(_Err __e)
# if _CCCL_CUDA_COMPILER(CLANG) // Clang needs this or it breaks with device only types
_CCCL_HOST_DEVICE
# endif // _CCCL_CUDA_COMPILER(CLANG)
_CCCL_HIDE_FROM_ABI explicit bad_expected_access(_Err __e)
: __unex_(_CUDA_VSTD::move(__e))
{}

# if _CCCL_CUDA_COMPILER(CLANG) // Clang needs this or it breaks with device only types
_CCCL_HOST_DEVICE
# endif // _CCCL_CUDA_COMPILER(CLANG)
_CCCL_HIDE_FROM_ABI ~bad_expected_access() noexcept
{
__unex_.~_Err();
}

_LIBCUDACXX_HIDE_FROM_ABI _Err& error() & noexcept
{
return __unex_;
Expand Down
20 changes: 20 additions & 0 deletions libcudacxx/include/cuda/std/__expected/expected.h
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,7 @@ class expected : private __expected_move_assign<_Tp, _Err>
}

// [expected.object.eq], equality operators
_CCCL_EXEC_CHECK_DISABLE
friend _LIBCUDACXX_HIDE_FROM_ABI constexpr bool operator==(const expected& __x, const expected& __y)
{
if (__x.__has_val_ != __y.has_value())
Expand All @@ -1090,12 +1091,14 @@ class expected : private __expected_move_assign<_Tp, _Err>
}

# if _CCCL_STD_VER < 2020
_CCCL_EXEC_CHECK_DISABLE
friend _LIBCUDACXX_HIDE_FROM_ABI constexpr bool operator!=(const expected& __x, const expected& __y)
{
return !(__x == __y);
}
# endif // _CCCL_STD_VER < 2020

_CCCL_EXEC_CHECK_DISABLE
_CCCL_TEMPLATE(class _T2, class _E2)
_CCCL_REQUIRES((!_CCCL_TRAIT(is_void, _T2)))
friend _LIBCUDACXX_HIDE_FROM_ABI constexpr bool operator==(const expected& __x, const expected<_T2, _E2>& __y)
Expand All @@ -1118,6 +1121,7 @@ class expected : private __expected_move_assign<_Tp, _Err>
}

# if _CCCL_STD_VER < 2020
_CCCL_EXEC_CHECK_DISABLE
_CCCL_TEMPLATE(class _T2, class _E2)
_CCCL_REQUIRES((!_CCCL_TRAIT(is_void, _T2)))
friend _LIBCUDACXX_HIDE_FROM_ABI constexpr bool operator!=(const expected& __x, const expected<_T2, _E2>& __y)
Expand All @@ -1126,25 +1130,29 @@ class expected : private __expected_move_assign<_Tp, _Err>
}
# endif // _CCCL_STD_VER < 2020

_CCCL_EXEC_CHECK_DISABLE
_CCCL_TEMPLATE(class _T2)
_CCCL_REQUIRES((!__expected::__is_expected_nonvoid<_T2>) )
friend _LIBCUDACXX_HIDE_FROM_ABI constexpr bool operator==(const expected& __x, const _T2& __v)
{
return __x.__has_val_ && static_cast<bool>(__x.__union_.__val_ == __v);
}
# if _CCCL_STD_VER < 2020
_CCCL_EXEC_CHECK_DISABLE
_CCCL_TEMPLATE(class _T2)
_CCCL_REQUIRES((!__expected::__is_expected_nonvoid<_T2>) )
friend _LIBCUDACXX_HIDE_FROM_ABI constexpr bool operator==(const _T2& __v, const expected& __x)
{
return __x.__has_val_ && static_cast<bool>(__x.__union_.__val_ == __v);
}
_CCCL_EXEC_CHECK_DISABLE
_CCCL_TEMPLATE(class _T2)
_CCCL_REQUIRES((!__expected::__is_expected_nonvoid<_T2>) )
friend _LIBCUDACXX_HIDE_FROM_ABI constexpr bool operator!=(const expected& __x, const _T2& __v)
{
return !__x.__has_val_ || static_cast<bool>(__x.__union_.__val_ != __v);
}
_CCCL_EXEC_CHECK_DISABLE
_CCCL_TEMPLATE(class _T2)
_CCCL_REQUIRES((!__expected::__is_expected_nonvoid<_T2>) )
friend _LIBCUDACXX_HIDE_FROM_ABI constexpr bool operator!=(const _T2& __v, const expected& __x)
Expand All @@ -1153,22 +1161,26 @@ class expected : private __expected_move_assign<_Tp, _Err>
}
# endif // _CCCL_STD_VER < 2020

_CCCL_EXEC_CHECK_DISABLE
template <class _E2>
friend _LIBCUDACXX_HIDE_FROM_ABI constexpr bool operator==(const expected& __x, const unexpected<_E2>& __e)
{
return !__x.__has_val_ && static_cast<bool>(__x.__union_.__unex_ == __e.error());
}
# if _CCCL_STD_VER < 2020
_CCCL_EXEC_CHECK_DISABLE
template <class _E2>
friend _LIBCUDACXX_HIDE_FROM_ABI constexpr bool operator==(const unexpected<_E2>& __e, const expected& __x)
{
return !__x.__has_val_ && static_cast<bool>(__x.__union_.__unex_ == __e.error());
}
_CCCL_EXEC_CHECK_DISABLE
template <class _E2>
friend _LIBCUDACXX_HIDE_FROM_ABI constexpr bool operator!=(const expected& __x, const unexpected<_E2>& __e)
{
return __x.__has_val_ || static_cast<bool>(__x.__union_.__unex_ != __e.error());
}
_CCCL_EXEC_CHECK_DISABLE
template <class _E2>
friend _LIBCUDACXX_HIDE_FROM_ABI constexpr bool operator!=(const unexpected<_E2>& __e, const expected& __x)
{
Expand Down Expand Up @@ -1906,6 +1918,7 @@ class expected<void, _Err> : private __expected_move_assign<void, _Err>
}

// [expected.void.eq], equality operators
_CCCL_EXEC_CHECK_DISABLE
friend _LIBCUDACXX_HIDE_FROM_ABI constexpr bool operator==(const expected& __x, const expected& __y) noexcept
{
if (__x.__has_val_ != __y.has_value())
Expand All @@ -1918,12 +1931,14 @@ class expected<void, _Err> : private __expected_move_assign<void, _Err>
}
}
# if _CCCL_STD_VER < 2020
_CCCL_EXEC_CHECK_DISABLE
friend _LIBCUDACXX_HIDE_FROM_ABI constexpr bool operator!=(const expected& __x, const expected& __y) noexcept
{
return !(__x == __y);
}
# endif

_CCCL_EXEC_CHECK_DISABLE
template <class _E2>
friend _LIBCUDACXX_HIDE_FROM_ABI constexpr bool
operator==(const expected& __x, const expected<void, _E2>& __y) noexcept
Expand All @@ -1938,6 +1953,7 @@ class expected<void, _Err> : private __expected_move_assign<void, _Err>
}
}
# if _CCCL_STD_VER < 2020
_CCCL_EXEC_CHECK_DISABLE
template <class _E2>
friend _LIBCUDACXX_HIDE_FROM_ABI constexpr bool
operator!=(const expected& __x, const expected<void, _E2>& __y) noexcept
Expand All @@ -1946,22 +1962,26 @@ class expected<void, _Err> : private __expected_move_assign<void, _Err>
}
# endif

_CCCL_EXEC_CHECK_DISABLE
template <class _E2>
friend _LIBCUDACXX_HIDE_FROM_ABI constexpr bool operator==(const expected& __x, const unexpected<_E2>& __y) noexcept
{
return !__x.__has_val_ && static_cast<bool>(__x.__union_.__unex_ == __y.error());
}
# if _CCCL_STD_VER < 2020
_CCCL_EXEC_CHECK_DISABLE
template <class _E2>
friend _LIBCUDACXX_HIDE_FROM_ABI constexpr bool operator==(const unexpected<_E2>& __y, const expected& __x) noexcept
{
return !__x.__has_val_ && static_cast<bool>(__x.__union_.__unex_ == __y.error());
}
_CCCL_EXEC_CHECK_DISABLE
template <class _E2>
_LIBCUDACXX_HIDE_FROM_ABI friend constexpr bool operator!=(const expected& __x, const unexpected<_E2>& __y) noexcept
{
return __x.__has_val_ || static_cast<bool>(__x.__union_.__unex_ != __y.error());
}
_CCCL_EXEC_CHECK_DISABLE
template <class _E2>
_LIBCUDACXX_HIDE_FROM_ABI friend constexpr bool operator!=(const unexpected<_E2>& __y, const expected& __x) noexcept
{
Expand Down
18 changes: 18 additions & 0 deletions libcudacxx/include/cuda/std/__expected/expected_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,30 +71,35 @@ union __expected_union_t
struct __empty_t
{};

_CCCL_EXEC_CHECK_DISABLE
_CCCL_TEMPLATE(class _Tp2 = _Tp)
_CCCL_REQUIRES(_CCCL_TRAIT(is_default_constructible, _Tp2))
_LIBCUDACXX_HIDE_FROM_ABI constexpr __expected_union_t() noexcept(_CCCL_TRAIT(is_nothrow_default_constructible, _Tp2))
: __val_()
{}

_CCCL_EXEC_CHECK_DISABLE
_CCCL_TEMPLATE(class _Tp2 = _Tp)
_CCCL_REQUIRES((!_CCCL_TRAIT(is_default_constructible, _Tp2)))
_LIBCUDACXX_HIDE_FROM_ABI constexpr __expected_union_t() noexcept
: __empty_()
{}

_CCCL_EXEC_CHECK_DISABLE
template <class... _Args>
_LIBCUDACXX_HIDE_FROM_ABI constexpr __expected_union_t(in_place_t, _Args&&... __args) noexcept(
_CCCL_TRAIT(is_nothrow_constructible, _Tp, _Args...))
: __val_(_CUDA_VSTD::forward<_Args>(__args)...)
{}

_CCCL_EXEC_CHECK_DISABLE
template <class... _Args>
_LIBCUDACXX_HIDE_FROM_ABI constexpr __expected_union_t(unexpect_t, _Args&&... __args) noexcept(
_CCCL_TRAIT(is_nothrow_constructible, _Err, _Args...))
: __unex_(_CUDA_VSTD::forward<_Args>(__args)...)
{}

_CCCL_EXEC_CHECK_DISABLE
template <class _Fun, class... _Args>
_LIBCUDACXX_HIDE_FROM_ABI constexpr __expected_union_t(
__expected_construct_from_invoke_tag,
Expand All @@ -104,6 +109,7 @@ union __expected_union_t
: __val_(_CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fun>(__fun), _CUDA_VSTD::forward<_Args>(__args)...))
{}

_CCCL_EXEC_CHECK_DISABLE
template <class _Fun, class... _Args>
_LIBCUDACXX_HIDE_FROM_ABI constexpr __expected_union_t(
__expected_construct_from_invoke_tag,
Expand All @@ -128,18 +134,21 @@ union __expected_union_t<_Tp, _Err, true>
struct __empty_t
{};

_CCCL_EXEC_CHECK_DISABLE
_CCCL_TEMPLATE(class _Tp2 = _Tp)
_CCCL_REQUIRES(_CCCL_TRAIT(is_default_constructible, _Tp2))
_LIBCUDACXX_HIDE_FROM_ABI constexpr __expected_union_t() noexcept(_CCCL_TRAIT(is_nothrow_default_constructible, _Tp2))
: __val_()
{}

_CCCL_EXEC_CHECK_DISABLE
_CCCL_TEMPLATE(class _Tp2 = _Tp)
_CCCL_REQUIRES((!_CCCL_TRAIT(is_default_constructible, _Tp2)))
_LIBCUDACXX_HIDE_FROM_ABI constexpr __expected_union_t() noexcept
: __empty_()
{}

_CCCL_EXEC_CHECK_DISABLE
template <class... _Args>
_LIBCUDACXX_HIDE_FROM_ABI constexpr __expected_union_t(in_place_t, _Args&&... __args) noexcept(
_CCCL_TRAIT(is_nothrow_constructible, _Tp, _Args...))
Expand All @@ -152,6 +161,7 @@ union __expected_union_t<_Tp, _Err, true>
: __unex_(_CUDA_VSTD::forward<_Args>(__args)...)
{}

_CCCL_EXEC_CHECK_DISABLE
template <class _Fun, class... _Args>
_LIBCUDACXX_HIDE_FROM_ABI constexpr __expected_union_t(
__expected_construct_from_invoke_tag,
Expand All @@ -161,6 +171,7 @@ union __expected_union_t<_Tp, _Err, true>
: __val_(_CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fun>(__fun), _CUDA_VSTD::forward<_Args>(__args)...))
{}

_CCCL_EXEC_CHECK_DISABLE
template <class _Fun, class... _Args>
_LIBCUDACXX_HIDE_FROM_ABI constexpr __expected_union_t(
__expected_construct_from_invoke_tag,
Expand Down Expand Up @@ -436,6 +447,7 @@ struct __expected_storage : __expected_destruct<_Tp, _Err>
{
_LIBCUDACXX_DELEGATE_CONSTRUCTORS(__expected_storage, __expected_destruct, _Tp, _Err);

_CCCL_EXEC_CHECK_DISABLE
_CCCL_TEMPLATE(class _T1, class _T2, class... _Args)
_CCCL_REQUIRES(_CCCL_TRAIT(is_nothrow_constructible, _T1, _Args...))
static _LIBCUDACXX_HIDE_FROM_ABI _CCCL_CONSTEXPR_CXX20 void
Expand All @@ -445,6 +457,7 @@ struct __expected_storage : __expected_destruct<_Tp, _Err>
_LIBCUDACXX_CONSTRUCT_AT(__newval, _CUDA_VSTD::forward<_Args>(__args)...);
}

_CCCL_EXEC_CHECK_DISABLE
_CCCL_TEMPLATE(class _T1, class _T2, class... _Args)
_CCCL_REQUIRES(
(!_CCCL_TRAIT(is_nothrow_constructible, _T1, _Args...)) _CCCL_AND _CCCL_TRAIT(is_nothrow_move_constructible, _T1))
Expand All @@ -456,6 +469,7 @@ struct __expected_storage : __expected_destruct<_Tp, _Err>
_LIBCUDACXX_CONSTRUCT_AT(__newval, _CUDA_VSTD::move(__tmp));
}

_CCCL_EXEC_CHECK_DISABLE
_CCCL_TEMPLATE(class _T1, class _T2, class... _Args)
_CCCL_REQUIRES(
(!_CCCL_TRAIT(is_nothrow_constructible, _T1, _Args...)) _CCCL_AND(!_CCCL_TRAIT(is_nothrow_move_constructible, _T1)))
Expand All @@ -475,6 +489,7 @@ struct __expected_storage : __expected_destruct<_Tp, _Err>
__trans.__complete();
}

_CCCL_EXEC_CHECK_DISABLE
_CCCL_TEMPLATE(class _Err2 = _Err)
_CCCL_REQUIRES(_CCCL_TRAIT(is_nothrow_move_constructible, _Err2))
static _LIBCUDACXX_HIDE_FROM_ABI _CCCL_CONSTEXPR_CXX20 void
Expand All @@ -493,6 +508,7 @@ struct __expected_storage : __expected_destruct<_Tp, _Err>
__with_err.__has_val_ = true;
}

_CCCL_EXEC_CHECK_DISABLE
_CCCL_TEMPLATE(class _Err2 = _Err)
_CCCL_REQUIRES((!_CCCL_TRAIT(is_nothrow_move_constructible, _Err2)))
static _LIBCUDACXX_HIDE_FROM_ABI _CCCL_CONSTEXPR_CXX20 void
Expand Down Expand Up @@ -653,6 +669,7 @@ struct __expected_copy_assign<_Tp, _Err, __smf_availability::__available> : __ex
_CCCL_HIDE_FROM_ABI __expected_copy_assign(const __expected_copy_assign&) = default;
_CCCL_HIDE_FROM_ABI __expected_copy_assign(__expected_copy_assign&&) = default;

_CCCL_EXEC_CHECK_DISABLE
_LIBCUDACXX_HIDE_FROM_ABI _CCCL_CONSTEXPR_CXX20 __expected_copy_assign&
operator=(const __expected_copy_assign& __other) noexcept(
_CCCL_TRAIT(is_nothrow_copy_assignable, _Tp) && _CCCL_TRAIT(is_nothrow_copy_constructible, _Tp)
Expand Down Expand Up @@ -917,6 +934,7 @@ struct __expected_storage<void, _Err> : __expected_destruct<void, _Err>
{
_LIBCUDACXX_DELEGATE_CONSTRUCTORS(__expected_storage, __expected_destruct, void, _Err);

_CCCL_EXEC_CHECK_DISABLE
static _LIBCUDACXX_HIDE_FROM_ABI _CCCL_CONSTEXPR_CXX20 void __swap_val_unex_impl(
__expected_storage& __with_val,
__expected_storage& __with_err) noexcept(_CCCL_TRAIT(is_nothrow_move_constructible, _Err))
Expand Down
7 changes: 7 additions & 0 deletions libcudacxx/include/cuda/std/__expected/unexpected.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class unexpected
_CCCL_HIDE_FROM_ABI unexpected(const unexpected&) = default;
_CCCL_HIDE_FROM_ABI unexpected(unexpected&&) = default;

_CCCL_EXEC_CHECK_DISABLE
_CCCL_TEMPLATE(class _Error = _Err)
_CCCL_REQUIRES((!_CCCL_TRAIT(is_same, remove_cvref_t<_Error>, unexpected)
&& !_CCCL_TRAIT(is_same, remove_cvref_t<_Error>, in_place_t)
Expand All @@ -82,13 +83,15 @@ class unexpected
: __unex_(_CUDA_VSTD::forward<_Error>(__error))
{}

_CCCL_EXEC_CHECK_DISABLE
_CCCL_TEMPLATE(class... _Args)
_CCCL_REQUIRES(_CCCL_TRAIT(is_constructible, _Err, _Args...))
_LIBCUDACXX_HIDE_FROM_ABI constexpr explicit unexpected(in_place_t, _Args&&... __args) noexcept(
_CCCL_TRAIT(is_nothrow_constructible, _Err, _Args...))
: __unex_(_CUDA_VSTD::forward<_Args>(__args)...)
{}

_CCCL_EXEC_CHECK_DISABLE
_CCCL_TEMPLATE(class _Up, class... _Args)
_CCCL_REQUIRES(_CCCL_TRAIT(is_constructible, _Err, initializer_list<_Up>&, _Args...))
_LIBCUDACXX_HIDE_FROM_ABI constexpr explicit unexpected(
Expand Down Expand Up @@ -123,13 +126,15 @@ class unexpected
}

// [expected.un.swap]
_CCCL_EXEC_CHECK_DISABLE
_LIBCUDACXX_HIDE_FROM_ABI constexpr void swap(unexpected& __other) noexcept(_CCCL_TRAIT(is_nothrow_swappable, _Err))
{
static_assert(_CCCL_TRAIT(is_swappable, _Err), "E must be swappable");
using _CUDA_VSTD::swap;
swap(__unex_, __other.__unex_);
}

_CCCL_EXEC_CHECK_DISABLE
_CCCL_TEMPLATE(class _Err2 = _Err)
_CCCL_REQUIRES(_CCCL_TRAIT(is_swappable, _Err2))
friend _LIBCUDACXX_HIDE_FROM_ABI constexpr void
Expand All @@ -140,6 +145,7 @@ class unexpected
}

// [expected.un.eq]
_CCCL_EXEC_CHECK_DISABLE
template <class _UErr>
_CCCL_NODISCARD_FRIEND _LIBCUDACXX_HIDE_FROM_ABI constexpr bool
operator==(const unexpected& __lhs,
Expand All @@ -148,6 +154,7 @@ class unexpected
return __lhs.error() == __rhs.error();
}
# if _CCCL_STD_VER < 2020
_CCCL_EXEC_CHECK_DISABLE
template <class _UErr>
_CCCL_NODISCARD_FRIEND _LIBCUDACXX_HIDE_FROM_ABI constexpr bool
operator!=(const unexpected& __lhs,
Expand Down
1 change: 1 addition & 0 deletions libcudacxx/include/cuda/std/__memory/construct_at.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
# ifndef __cpp_lib_constexpr_dynamic_alloc
namespace std
{
_CCCL_EXEC_CHECK_DISABLE
template <class _Tp,
class... _Args,
class = decltype(::new(_CUDA_VSTD::declval<void*>()) _Tp(_CUDA_VSTD::declval<_Args>()...))>
Expand Down
Loading

0 comments on commit b6209e8

Please sign in to comment.