Skip to content

Commit 5ebc18c

Browse files
Deprecate thrust::optional (#3307) (#3393)
Fixes: #3306
1 parent 9092760 commit 5ebc18c

File tree

2 files changed

+51
-14
lines changed

2 files changed

+51
-14
lines changed

thrust/thrust/optional.h

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
#include <type_traits>
3838
#include <utility>
3939

40+
_CCCL_SUPPRESS_DEPRECATED_PUSH
41+
4042
#if _CCCL_COMPILER(MSVC, ==, 19, 00)
4143
# define THRUST_OPTIONAL_MSVC2015
4244
#endif
@@ -59,11 +61,11 @@ THRUST_NAMESPACE_BEGIN
5961
#ifndef THRUST_MONOSTATE_INPLACE_MUTEX
6062
# define THRUST_MONOSTATE_INPLACE_MUTEX
6163
/// \brief Used to represent an optional with no data; essentially a bool
62-
class monostate
64+
class CCCL_DEPRECATED_BECAUSE("Use cuda::std::monostate instead") monostate
6365
{};
6466

6567
/// \brief A tag type to tell optional to construct its value in-place
66-
struct in_place_t
68+
struct CCCL_DEPRECATED in_place_t
6769
{
6870
explicit in_place_t() = default;
6971
};
@@ -72,7 +74,7 @@ static constexpr in_place_t in_place{};
7274
#endif
7375

7476
template <class T>
75-
class optional;
77+
class CCCL_DEPRECATED_BECAUSE("Use cuda::std::optional") optional;
7678

7779
/// \exclude
7880
namespace detail
@@ -720,7 +722,7 @@ struct optional_delete_assign_base<T, false, false>
720722
} // namespace detail
721723

722724
/// \brief A tag type to represent an empty optional
723-
struct nullopt_t
725+
struct CCCL_DEPRECATED nullopt_t
724726
{
725727
struct do_not_use
726728
{};
@@ -742,7 +744,7 @@ static constexpr
742744
#endif // __CUDA_ARCH__
743745
nullopt_t nullopt{nullopt_t::do_not_use{}, nullopt_t::do_not_use{}};
744746

745-
class bad_optional_access : public std::exception
747+
class CCCL_DEPRECATED bad_optional_access : public std::exception
746748
{
747749
public:
748750
bad_optional_access() = default;
@@ -1952,19 +1954,22 @@ _CCCL_EXEC_CHECK_DISABLE
19521954
template <class T = detail::i_am_secret,
19531955
class U,
19541956
class Ret = detail::conditional_t<std::is_same<T, detail::i_am_secret>::value, detail::decay_t<U>, T>>
1957+
CCCL_DEPRECATED_BECAUSE("Use cuda::std::make_optional")
19551958
_CCCL_HOST_DEVICE inline constexpr optional<Ret> make_optional(U&& v)
19561959
{
19571960
return optional<Ret>(std::forward<U>(v));
19581961
}
19591962

19601963
_CCCL_EXEC_CHECK_DISABLE
19611964
template <class T, class... Args>
1965+
CCCL_DEPRECATED_BECAUSE("Use cuda::std::make_optional")
19621966
_CCCL_HOST_DEVICE inline constexpr optional<T> make_optional(Args&&... args)
19631967
{
19641968
return optional<T>(in_place, std::forward<Args>(args)...);
19651969
}
19661970
_CCCL_EXEC_CHECK_DISABLE
19671971
template <class T, class U, class... Args>
1972+
CCCL_DEPRECATED_BECAUSE("Use cuda::std::make_optional")
19681973
_CCCL_HOST_DEVICE inline constexpr optional<T> make_optional(std::initializer_list<U> il, Args&&... args)
19691974
{
19701975
return optional<T>(in_place, il, std::forward<Args>(args)...);
@@ -2001,7 +2006,22 @@ _CCCL_HOST_DEVICE auto optional_map_impl(Opt&& opt, F&& f)
20012006
if (opt.has_value())
20022007
{
20032008
detail::invoke(std::forward<F>(f), *std::forward<Opt>(opt));
2009+
# if _CCCL_COMPILER(MSVC)
2010+
// MSVC fails to suppress the warning on make_optional
2011+
_CCCL_SUPPRESS_DEPRECATED_PUSH
2012+
return optional<monostate>(monostate{});
2013+
_CCCL_SUPPRESS_DEPRECATED_POP
2014+
# elif _CCCL_COMPILER(NVHPC)
2015+
// NVHPC cannot have a diagnostic pop after a return statement
2016+
_CCCL_SUPPRESS_DEPRECATED_PUSH
2017+
auto o = optional<monostate>(monostate{});
2018+
_CCCL_SUPPRESS_DEPRECATED_POP
2019+
return ::cuda::std::move(o);
2020+
# else
2021+
_CCCL_SUPPRESS_DEPRECATED_PUSH
20042022
return make_optional(monostate{});
2023+
_CCCL_SUPPRESS_DEPRECATED_POP
2024+
# endif
20052025
}
20062026

20072027
return optional<monostate>(nullopt);
@@ -2820,3 +2840,5 @@ struct hash<THRUST_NS_QUALIFIER::optional<T>>
28202840
}
28212841
};
28222842
} // namespace std
2843+
2844+
_CCCL_SUPPRESS_DEPRECATED_POP

thrust/thrust/system/cuda/detail/future.inl

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,9 @@ struct unique_eager_future_promise_pair final
310310
weak_promise<X, XPointer> promise;
311311
};
312312

313-
struct acquired_stream final
313+
_CCCL_SUPPRESS_DEPRECATED_PUSH // for thrust::optional
314+
315+
struct acquired_stream final
314316
{
315317
unique_stream stream;
316318
optional<std::size_t> const acquired_from;
@@ -340,6 +342,8 @@ inline _CCCL_HOST optional<unique_stream> try_acquire_stream(int device, unique_
340342
template <typename X>
341343
_CCCL_HOST optional<unique_stream> try_acquire_stream(int device, unique_eager_future<X>& parent) noexcept;
342344

345+
_CCCL_SUPPRESS_DEPRECATED_POP
346+
343347
template <typename... Dependencies>
344348
_CCCL_HOST acquired_stream acquire_stream(int device, Dependencies&... deps) noexcept;
345349

@@ -744,8 +748,10 @@ public:
744748
stream().wait();
745749
}
746750

747-
friend _CCCL_HOST optional<detail::unique_stream>
748-
thrust::system::cuda::detail::try_acquire_stream(int device_id, unique_eager_event& parent) noexcept;
751+
_CCCL_SUPPRESS_DEPRECATED_PUSH // for thrust::optional
752+
friend _CCCL_HOST optional<detail::unique_stream>
753+
thrust::system::cuda::detail::try_acquire_stream(int device_id, unique_eager_event& parent) noexcept;
754+
_CCCL_SUPPRESS_DEPRECATED_POP
749755

750756
template <typename... Dependencies>
751757
friend _CCCL_HOST unique_eager_event
@@ -902,9 +908,11 @@ public:
902908
}
903909
# endif
904910

905-
template <typename X>
906-
friend _CCCL_HOST optional<detail::unique_stream>
907-
thrust::system::cuda::detail::try_acquire_stream(int device_id, unique_eager_future<X>& parent) noexcept;
911+
_CCCL_SUPPRESS_DEPRECATED_PUSH // for thrust::optional
912+
template <typename X>
913+
friend _CCCL_HOST optional<detail::unique_stream>
914+
thrust::system::cuda::detail::try_acquire_stream(int device_id, unique_eager_future<X>& parent) noexcept;
915+
_CCCL_SUPPRESS_DEPRECATED_POP
908916

909917
template <typename X, typename XPointer, typename ComputeContent, typename... Dependencies>
910918
friend _CCCL_HOST detail::unique_eager_future_promise_pair<X, XPointer>
@@ -917,9 +925,10 @@ public:
917925

918926
namespace detail
919927
{
928+
_CCCL_SUPPRESS_DEPRECATED_PUSH // for thrust::optional
920929

921-
template <typename X, typename Deleter>
922-
_CCCL_HOST optional<unique_stream> try_acquire_stream(int, std::unique_ptr<X, Deleter>&) noexcept
930+
template <typename X, typename Deleter>
931+
_CCCL_HOST optional<unique_stream> try_acquire_stream(int, std::unique_ptr<X, Deleter>&) noexcept
923932
{
924933
// There's no stream to acquire!
925934
return {};
@@ -974,6 +983,8 @@ _CCCL_HOST optional<unique_stream> try_acquire_stream(int device_id, unique_eage
974983
return {};
975984
}
976985

986+
_CCCL_SUPPRESS_DEPRECATED_POP
987+
977988
///////////////////////////////////////////////////////////////////////////////
978989

979990
template <typename... Dependencies>
@@ -988,7 +999,8 @@ template <typename... Dependencies, std::size_t I0, std::size_t... Is>
988999
_CCCL_HOST acquired_stream
9891000
acquire_stream_impl(int device_id, std::tuple<Dependencies...>& deps, index_sequence<I0, Is...>) noexcept
9901001
{
991-
auto tr = try_acquire_stream(device_id, std::get<I0>(deps));
1002+
_CCCL_SUPPRESS_DEPRECATED_PUSH // for thrust::optional (MSVC warnings here)
1003+
auto tr = try_acquire_stream(device_id, std::get<I0>(deps));
9921004

9931005
if (tr)
9941006
{
@@ -998,6 +1010,7 @@ acquire_stream_impl(int device_id, std::tuple<Dependencies...>& deps, index_sequ
9981010
{
9991011
return acquire_stream_impl(device_id, deps, index_sequence<Is...>{});
10001012
}
1013+
_CCCL_SUPPRESS_DEPRECATED_POP
10011014
}
10021015

10031016
template <typename... Dependencies>
@@ -1044,10 +1057,12 @@ create_dependencies_impl(acquired_stream& as, std::tuple<Dependencies...>& deps,
10441057
{
10451058
// We only need to wait on the current dependency if we didn't steal our
10461059
// stream from it.
1060+
_CCCL_SUPPRESS_DEPRECATED_PUSH
10471061
if (!as.acquired_from || *as.acquired_from != I0)
10481062
{
10491063
create_dependency(as.stream, std::get<I0>(deps));
10501064
}
1065+
_CCCL_SUPPRESS_DEPRECATED_POP
10511066

10521067
create_dependencies_impl(as, deps, index_sequence<Is...>{});
10531068
}

0 commit comments

Comments
 (0)