Skip to content
This repository was archived by the owner on Mar 21, 2024. It is now read-only.

Commit c717f49

Browse files
authored
Merge pull request #1760 from senior-zero/fix-main/github/device_lambdas
Emit diagnostics for device lambdas
2 parents 0bebe52 + a78f219 commit c717f49

File tree

6 files changed

+27
-53
lines changed

6 files changed

+27
-53
lines changed

thrust/detail/type_traits.h

+18-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2008-2018 NVIDIA Corporation
2+
* Copyright 2008-2022 NVIDIA Corporation
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,9 +24,9 @@
2424

2525
#include <thrust/detail/config.h>
2626

27-
#if THRUST_CPP_DIALECT >= 2011
28-
# include <type_traits>
29-
#endif
27+
#include <cuda/std/type_traits>
28+
29+
#include <type_traits>
3030

3131
THRUST_NAMESPACE_BEGIN
3232

@@ -47,7 +47,6 @@ namespace detail
4747
// We don't want to switch to std::integral_constant, because we want access
4848
// to the C++14 operator(), but we'd like standard traits to interoperate
4949
// with our version when tag dispatching.
50-
#if THRUST_CPP_DIALECT >= 2011
5150
integral_constant() = default;
5251

5352
integral_constant(integral_constant const&) = default;
@@ -56,7 +55,6 @@ namespace detail
5655

5756
constexpr __host__ __device__
5857
integral_constant(std::integral_constant<T, v>) noexcept {}
59-
#endif
6058

6159
constexpr __host__ __device__ operator value_type() const noexcept { return value; }
6260
constexpr __host__ __device__ value_type operator()() const noexcept { return value; }
@@ -715,6 +713,20 @@ template<typename T>
715713
{
716714
};
717715

716+
template <typename Invokable, typename... Args>
717+
using invoke_result_t =
718+
#if THRUST_CPP_DIALECT < 2017
719+
typename cuda::std::result_of<Invokable(Args...)>::type;
720+
#else // 2017+
721+
cuda::std::invoke_result_t<Invokable, Args...>;
722+
#endif
723+
724+
template <class F, class... Us>
725+
struct invoke_result
726+
{
727+
using type = invoke_result_t<F, Us...>;
728+
};
729+
718730
} // end detail
719731

720732
using detail::integral_constant;

thrust/detail/type_traits/result_of_adaptable_function.h

+1-6
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ namespace detail
2929
// Sets `type` to the result of the specified Signature invocation. If the
3030
// callable defines a `result_type` alias member, that type is used instead.
3131
// Use invoke_result / result_of when FuncType::result_type is not defined.
32-
#if THRUST_CPP_DIALECT >= 2017
3332
template <typename Signature, typename Enable = void>
3433
struct result_of_adaptable_function
3534
{
@@ -39,16 +38,12 @@ struct result_of_adaptable_function
3938
template <typename F, typename...Args>
4039
struct impl<F(Args...)>
4140
{
42-
using type = std::invoke_result_t<F, Args...>;
41+
using type = invoke_result_t<F, Args...>;
4342
};
4443

4544
public:
4645
using type = typename impl<Signature>::type;
4746
};
48-
#else // < C++17
49-
template <typename Signature, typename Enable = void>
50-
struct result_of_adaptable_function : std::result_of<Signature> {};
51-
#endif // < C++17
5247

5348
// specialization for invocations which define result_type
5449
template <typename Functor, typename... ArgTypes>

thrust/iterator/detail/transform_input_output_iterator.inl

+3-13
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
#pragma once
1818

1919
#include <thrust/detail/config.h>
20-
2120
#include <thrust/iterator/iterator_adaptor.h>
21+
#include <thrust/detail/type_traits.h>
2222

2323
THRUST_NAMESPACE_BEGIN
2424

@@ -35,12 +35,7 @@ template <typename InputFunction, typename OutputFunction, typename Iterator>
3535
{
3636
using iterator_value_type = typename thrust::iterator_value<Iterator>::type;
3737

38-
// std::result_of is deprecated in 2017, replace with std::invoke_result
39-
#if THRUST_CPP_DIALECT < 2017
40-
using Value = typename std::result_of<InputFunction(iterator_value_type)>::type;
41-
#else
42-
using Value = std::invoke_result_t<InputFunction, iterator_value_type>;
43-
#endif
38+
using Value = invoke_result_t<InputFunction, iterator_value_type>;
4439

4540
public:
4641
__host__ __device__
@@ -93,12 +88,7 @@ public:
9388
<
9489
transform_input_output_iterator<InputFunction, OutputFunction, Iterator>
9590
, Iterator
96-
// std::result_of is deprecated in 2017, replace with std::invoke_result
97-
#if THRUST_CPP_DIALECT < 2017
98-
, typename std::result_of<InputFunction(iterator_value_type)>::type
99-
#else
100-
, std::invoke_result_t<InputFunction, iterator_value_type>
101-
#endif
91+
, detail::invoke_result_t<InputFunction, iterator_value_type>
10292
, thrust::use_default
10393
, thrust::use_default
10494
, transform_input_output_iterator_proxy<InputFunction, OutputFunction, Iterator>

thrust/optional.h

+1-16
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include <thrust/detail/config.h>
1717
#include <thrust/detail/cpp11_required.h>
18+
#include <thrust/detail/type_traits.h>
1819

1920
#if THRUST_CPP_DIALECT >= 2011
2021

@@ -255,22 +256,6 @@ constexpr auto invoke(Fn &&f, Args &&... args)
255256
{
256257
return std::forward<Fn>(f)(std::forward<Args>(args)...);
257258
}
258-
259-
// std::invoke_result from C++17
260-
template <class F, class, class... Us> struct invoke_result_impl;
261-
262-
template <class F, class... Us>
263-
struct invoke_result_impl<
264-
F, decltype(detail::invoke(std::declval<F>(), std::declval<Us>()...), void()),
265-
Us...> {
266-
using type = decltype(detail::invoke(std::declval<F>(), std::declval<Us>()...));
267-
};
268-
269-
template <class F, class... Us>
270-
using invoke_result = invoke_result_impl<F, void, Us...>;
271-
272-
template <class F, class... Us>
273-
using invoke_result_t = typename invoke_result<F, Us...>::type;
274259
#endif
275260

276261
// std::void_t from C++17

thrust/system/cuda/detail/transform_scan.h

+3-7
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@
3030

3131
#if THRUST_DEVICE_COMPILER == THRUST_DEVICE_COMPILER_NVCC
3232
#include <iterator>
33-
#include <thrust/system/cuda/detail/scan.h>
33+
#include <thrust/detail/type_traits.h>
3434
#include <thrust/distance.h>
35+
#include <thrust/system/cuda/detail/scan.h>
3536

3637
THRUST_NAMESPACE_BEGIN
3738

@@ -52,12 +53,7 @@ transform_inclusive_scan(execution_policy<Derived> &policy,
5253
{
5354
// Use the transformed input iterator's value type per https://wg21.link/P0571
5455
using input_type = typename thrust::iterator_value<InputIt>::type;
55-
#if THRUST_CPP_DIALECT < 2017
56-
using result_type = typename std::result_of<TransformOp(input_type)>::type;
57-
#else
58-
using result_type = std::invoke_result_t<TransformOp, input_type>;
59-
#endif
60-
56+
using result_type = thrust::detail::invoke_result_t<TransformOp, input_type>;
6157
using value_type = typename std::remove_reference<result_type>::type;
6258

6359
typedef typename iterator_traits<InputIt>::difference_type size_type;

thrust/system/detail/generic/transform_scan.inl

+1-5
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,7 @@ __host__ __device__
4949
{
5050
// Use the input iterator's value type per https://wg21.link/P0571
5151
using InputType = typename thrust::iterator_value<InputIterator>::type;
52-
#if THRUST_CPP_DIALECT < 2017
53-
using ResultType = typename std::result_of<UnaryFunction(InputType)>::type;
54-
#else
55-
using ResultType = std::invoke_result_t<UnaryFunction, InputType>;
56-
#endif
52+
using ResultType = thrust::detail::invoke_result_t<UnaryFunction, InputType>;
5753
using ValueType = typename std::remove_reference<ResultType>::type;
5854

5955
thrust::transform_iterator<UnaryFunction, InputIterator, ValueType> _first(first, unary_op);

0 commit comments

Comments
 (0)