Skip to content

Commit 2b10299

Browse files
authored
Apply clang-tidy autofixes (#15894)
This changeset is large, but it's not very substantial. It's all the automated fixes produced by clang-tidy using our script. The bulk of the changes are either adding `[[nodiscard]]` to many functions or changing const ref args to pass by value and then move in cases where the parameter is only used to set a value. There are also some places where clang-tidy preferred either more or less namespacing of objects depending on the current namespace. The goal is to enable clang-tidy in CI, which we made progress towards in #9860 but stalled in #10064. This PR contains the first set of changes that will required for such a check to pass. I've marked this PR as breaking because some of the functions now marked as `[[nodiscard]]` are public APIs, so if consumers were ignoring the return values they will now see warnings, and if they are compiling with warnings as errors then the builds will break. Contributes to #584 Authors: - Vyas Ramasubramani (https://github.com/vyasr) Approvers: - Bradley Dice (https://github.com/bdice) - Nghia Truong (https://github.com/ttnghia) URL: #15894
1 parent f7ba6ab commit 2b10299

File tree

261 files changed

+2911
-2151
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

261 files changed

+2911
-2151
lines changed

.pre-commit-config.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,20 @@ repos:
5656
- id: clang-format
5757
types_or: [c, c++, cuda]
5858
args: ["-fallback-style=none", "-style=file", "-i"]
59+
exclude: |
60+
(?x)^(
61+
^cpp/src/io/parquet/ipc/Schema_generated.h|
62+
^cpp/src/io/parquet/ipc/Message_generated.h|
63+
^cpp/include/cudf_test/cxxopts.hpp|
64+
)
5965
- repo: https://github.com/sirosen/texthooks
6066
rev: 0.6.6
6167
hooks:
6268
- id: fix-smartquotes
6369
exclude: |
6470
(?x)^(
71+
^cpp/src/io/parquet/ipc/Schema_generated.h|
72+
^cpp/src/io/parquet/ipc/Message_generated.h|
6573
^cpp/include/cudf_test/cxxopts.hpp|
6674
^python/cudf/cudf/tests/data/subword_tokenizer_data/.*|
6775
^python/cudf/cudf/tests/text/test_text_methods.py

cpp/include/cudf/ast/expressions.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020-2023, NVIDIA CORPORATION.
2+
* Copyright (c) 2020-2024, 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.
@@ -478,7 +478,10 @@ class operation : public expression {
478478
*
479479
* @return Vector of operands
480480
*/
481-
std::vector<std::reference_wrapper<expression const>> get_operands() const { return operands; }
481+
[[nodiscard]] std::vector<std::reference_wrapper<expression const>> get_operands() const
482+
{
483+
return operands;
484+
}
482485

483486
/**
484487
* @copydoc expression::accept

cpp/include/cudf/column/column_device_view.cuh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ class alignas(16) column_device_view : public detail::column_device_view_base {
442442
* @return string_view instance representing this element at this index
443443
*/
444444
template <typename T, CUDF_ENABLE_IF(std::is_same_v<T, string_view>)>
445-
__device__ T element(size_type element_index) const noexcept
445+
__device__ [[nodiscard]] T element(size_type element_index) const noexcept
446446
{
447447
size_type index = element_index + offset(); // account for this view's _offset
448448
char const* d_strings = static_cast<char const*>(_data);
@@ -501,7 +501,7 @@ class alignas(16) column_device_view : public detail::column_device_view_base {
501501
* @return dictionary32 instance representing this element at this index
502502
*/
503503
template <typename T, CUDF_ENABLE_IF(std::is_same_v<T, dictionary32>)>
504-
__device__ T element(size_type element_index) const noexcept
504+
__device__ [[nodiscard]] T element(size_type element_index) const noexcept
505505
{
506506
size_type index = element_index + offset(); // account for this view's _offset
507507
auto const indices = d_children[0];
@@ -519,7 +519,7 @@ class alignas(16) column_device_view : public detail::column_device_view_base {
519519
* @return numeric::fixed_point representing the element at this index
520520
*/
521521
template <typename T, CUDF_ENABLE_IF(cudf::is_fixed_point<T>())>
522-
__device__ T element(size_type element_index) const noexcept
522+
__device__ [[nodiscard]] T element(size_type element_index) const noexcept
523523
{
524524
using namespace numeric;
525525
using rep = typename T::rep;
@@ -858,7 +858,7 @@ class alignas(16) column_device_view : public detail::column_device_view_base {
858858
*/
859859
[[nodiscard]] __device__ device_span<column_device_view const> children() const noexcept
860860
{
861-
return device_span<column_device_view const>(d_children, _num_children);
861+
return {d_children, static_cast<std::size_t>(_num_children)};
862862
}
863863

864864
/**
@@ -1032,7 +1032,7 @@ class alignas(16) mutable_column_device_view : public detail::column_device_view
10321032
* @return Reference to the element at the specified index
10331033
*/
10341034
template <typename T, CUDF_ENABLE_IF(is_rep_layout_compatible<T>())>
1035-
__device__ T& element(size_type element_index) const noexcept
1035+
__device__ [[nodiscard]] T& element(size_type element_index) const noexcept
10361036
{
10371037
return data<T>()[element_index];
10381038
}

cpp/include/cudf/detail/aggregation/aggregation.hpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
#include <functional>
2626
#include <numeric>
27+
#include <utility>
2728

2829
namespace cudf {
2930
namespace detail {
@@ -510,7 +511,7 @@ class quantile_aggregation final : public groupby_aggregation, public reduce_agg
510511
void finalize(aggregation_finalizer& finalizer) const override { finalizer.visit(*this); }
511512

512513
private:
513-
size_t hash_impl() const
514+
[[nodiscard]] size_t hash_impl() const
514515
{
515516
return std::hash<int>{}(static_cast<int>(_interpolation)) ^
516517
std::accumulate(
@@ -596,7 +597,10 @@ class nunique_aggregation final : public groupby_aggregation,
596597
void finalize(aggregation_finalizer& finalizer) const override { finalizer.visit(*this); }
597598

598599
private:
599-
size_t hash_impl() const { return std::hash<int>{}(static_cast<int>(_null_handling)); }
600+
[[nodiscard]] size_t hash_impl() const
601+
{
602+
return std::hash<int>{}(static_cast<int>(_null_handling));
603+
}
600604
};
601605

602606
/**
@@ -638,7 +642,7 @@ class nth_element_aggregation final : public groupby_aggregation,
638642
void finalize(aggregation_finalizer& finalizer) const override { finalizer.visit(*this); }
639643

640644
private:
641-
size_t hash_impl() const
645+
[[nodiscard]] size_t hash_impl() const
642646
{
643647
return std::hash<size_type>{}(_n) ^ std::hash<int>{}(static_cast<int>(_null_handling));
644648
}
@@ -763,7 +767,10 @@ class collect_list_aggregation final : public rolling_aggregation,
763767
void finalize(aggregation_finalizer& finalizer) const override { finalizer.visit(*this); }
764768

765769
private:
766-
size_t hash_impl() const { return std::hash<int>{}(static_cast<int>(_null_handling)); }
770+
[[nodiscard]] size_t hash_impl() const
771+
{
772+
return std::hash<int>{}(static_cast<int>(_null_handling));
773+
}
767774
};
768775

769776
/**
@@ -813,7 +820,7 @@ class collect_set_aggregation final : public rolling_aggregation,
813820
void finalize(aggregation_finalizer& finalizer) const override { finalizer.visit(*this); }
814821

815822
protected:
816-
size_t hash_impl() const
823+
[[nodiscard]] size_t hash_impl() const
817824
{
818825
return std::hash<int>{}(static_cast<int>(_null_handling) ^ static_cast<int>(_nulls_equal) ^
819826
static_cast<int>(_nans_equal));
@@ -866,10 +873,10 @@ class lead_lag_aggregation final : public rolling_aggregation {
866873
class udf_aggregation final : public rolling_aggregation {
867874
public:
868875
udf_aggregation(aggregation::Kind type,
869-
std::string const& user_defined_aggregator,
876+
std::string user_defined_aggregator,
870877
data_type output_type)
871878
: aggregation{type},
872-
_source{user_defined_aggregator},
879+
_source{std::move(user_defined_aggregator)},
873880
_operator_name{(type == aggregation::PTX) ? "rolling_udf_ptx" : "rolling_udf_cuda"},
874881
_function_name{"rolling_udf"},
875882
_output_type{output_type}
@@ -973,7 +980,7 @@ class merge_sets_aggregation final : public groupby_aggregation, public reduce_a
973980
void finalize(aggregation_finalizer& finalizer) const override { finalizer.visit(*this); }
974981

975982
protected:
976-
size_t hash_impl() const
983+
[[nodiscard]] size_t hash_impl() const
977984
{
978985
return std::hash<int>{}(static_cast<int>(_nulls_equal) ^ static_cast<int>(_nans_equal));
979986
}
@@ -1046,7 +1053,7 @@ class covariance_aggregation final : public groupby_aggregation {
10461053
void finalize(aggregation_finalizer& finalizer) const override { finalizer.visit(*this); }
10471054

10481055
protected:
1049-
size_t hash_impl() const
1056+
[[nodiscard]] size_t hash_impl() const
10501057
{
10511058
return std::hash<size_type>{}(_min_periods) ^ std::hash<size_type>{}(_ddof);
10521059
}
@@ -1088,7 +1095,7 @@ class correlation_aggregation final : public groupby_aggregation {
10881095
void finalize(aggregation_finalizer& finalizer) const override { finalizer.visit(*this); }
10891096

10901097
protected:
1091-
size_t hash_impl() const
1098+
[[nodiscard]] size_t hash_impl() const
10921099
{
10931100
return std::hash<int>{}(static_cast<int>(_type)) ^ std::hash<size_type>{}(_min_periods);
10941101
}

cpp/include/cudf/detail/contiguous_split.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class metadata_builder {
104104
*
105105
* @returns A vector containing the serialized column metadata
106106
*/
107-
std::vector<uint8_t> build() const;
107+
[[nodiscard]] std::vector<uint8_t> build() const;
108108

109109
/**
110110
* @brief Clear the internal buffer containing all added metadata.

cpp/include/cudf/detail/normalizing_iterator.cuh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ struct alignas(16) base_normalator {
5151
*/
5252
CUDF_HOST_DEVICE inline Derived& operator++()
5353
{
54-
Derived& derived = static_cast<Derived&>(*this);
54+
auto& derived = static_cast<Derived&>(*this);
5555
derived.p_ += width_;
5656
return derived;
5757
}
@@ -71,7 +71,7 @@ struct alignas(16) base_normalator {
7171
*/
7272
CUDF_HOST_DEVICE inline Derived& operator--()
7373
{
74-
Derived& derived = static_cast<Derived&>(*this);
74+
auto& derived = static_cast<Derived&>(*this);
7575
derived.p_ -= width_;
7676
return derived;
7777
}
@@ -91,7 +91,7 @@ struct alignas(16) base_normalator {
9191
*/
9292
CUDF_HOST_DEVICE inline Derived& operator+=(difference_type offset)
9393
{
94-
Derived& derived = static_cast<Derived&>(*this);
94+
auto& derived = static_cast<Derived&>(*this);
9595
derived.p_ += offset * width_;
9696
return derived;
9797
}
@@ -121,7 +121,7 @@ struct alignas(16) base_normalator {
121121
*/
122122
CUDF_HOST_DEVICE inline Derived& operator-=(difference_type offset)
123123
{
124-
Derived& derived = static_cast<Derived&>(*this);
124+
auto& derived = static_cast<Derived&>(*this);
125125
derived.p_ -= offset * width_;
126126
return derived;
127127
}

cpp/include/cudf/detail/structs/utilities.hpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include <rmm/device_buffer.hpp>
2626
#include <rmm/resource_ref.hpp>
2727

28+
#include <utility>
29+
2830
namespace cudf::structs::detail {
2931

3032
enum class column_nullability {
@@ -112,12 +114,12 @@ class flattened_table {
112114
* @param columns_ Newly allocated columns to back the table_view
113115
* @param nullable_data_ Newly generated temporary data that needs to be kept alive
114116
*/
115-
flattened_table(table_view const& flattened_columns_,
117+
flattened_table(table_view flattened_columns_,
116118
std::vector<order> const& orders_,
117119
std::vector<null_order> const& null_orders_,
118120
std::vector<std::unique_ptr<column>>&& columns_,
119121
temporary_nullable_data&& nullable_data_)
120-
: _flattened_columns{flattened_columns_},
122+
: _flattened_columns{std::move(flattened_columns_)},
121123
_orders{orders_},
122124
_null_orders{null_orders_},
123125
_columns{std::move(columns_)},
@@ -170,11 +172,11 @@ class flattened_table {
170172
* orders, flattened null precedence, alongside the supporting columns and device_buffers
171173
* for the flattened table.
172174
*/
173-
[[nodiscard]] std::unique_ptr<flattened_table> flatten_nested_columns(
175+
[[nodiscard]] std::unique_ptr<cudf::structs::detail::flattened_table> flatten_nested_columns(
174176
table_view const& input,
175-
std::vector<order> const& column_order,
176-
std::vector<null_order> const& null_precedence,
177-
column_nullability nullability,
177+
std::vector<cudf::order> const& column_order,
178+
std::vector<cudf::null_order> const& null_precedence,
179+
cudf::structs::detail::column_nullability nullability,
178180
rmm::cuda_stream_view stream,
179181
rmm::device_async_resource_ref mr);
180182

@@ -194,11 +196,11 @@ class flattened_table {
194196
* @param mr Device memory resource used to allocate new device memory
195197
* @return A new column with potentially new null mask
196198
*/
197-
[[nodiscard]] std::unique_ptr<column> superimpose_nulls(bitmask_type const* null_mask,
198-
size_type null_count,
199-
std::unique_ptr<column>&& input,
200-
rmm::cuda_stream_view stream,
201-
rmm::device_async_resource_ref mr);
199+
[[nodiscard]] std::unique_ptr<cudf::column> superimpose_nulls(bitmask_type const* null_mask,
200+
cudf::size_type null_count,
201+
std::unique_ptr<cudf::column>&& input,
202+
rmm::cuda_stream_view stream,
203+
rmm::device_async_resource_ref mr);
202204

203205
/**
204206
* @brief Push down nulls from the given input column into its children columns, using bitwise AND.

cpp/include/cudf/detail/utilities/host_vector.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class rmm_host_allocator {
8282
using size_type = std::size_t; ///< The type used for the size of the allocation
8383
using difference_type = std::ptrdiff_t; ///< The type of the distance between two pointers
8484

85-
typedef cuda::std::true_type propagate_on_container_move_assignment;
85+
using propagate_on_container_move_assignment = cuda::std::true_type;
8686

8787
/**
8888
* @brief converts a `rmm_host_allocator<T>` to `rmm_host_allocator<U>`
@@ -147,7 +147,7 @@ class rmm_host_allocator {
147147
* @return The maximum number of objects that may be allocated
148148
* by a single call to \p allocate().
149149
*/
150-
constexpr inline size_type max_size() const
150+
[[nodiscard]] constexpr inline size_type max_size() const
151151
{
152152
return (std::numeric_limits<size_type>::max)() / sizeof(T);
153153
}

cpp/include/cudf/detail/utilities/stream_pool.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class cuda_stream_pool {
7373
*
7474
* @return the number of stream objects in the pool
7575
*/
76-
virtual std::size_t get_stream_pool_size() const = 0;
76+
[[nodiscard]] virtual std::size_t get_stream_pool_size() const = 0;
7777
};
7878

7979
/**

cpp/include/cudf/fixed_point/fixed_point.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,14 +291,14 @@ class fixed_point {
291291
*
292292
* @return The underlying value of the `fixed_point` number
293293
*/
294-
CUDF_HOST_DEVICE inline rep value() const { return _value; }
294+
CUDF_HOST_DEVICE [[nodiscard]] inline rep value() const { return _value; }
295295

296296
/**
297297
* @brief Method that returns the scale of the `fixed_point` number
298298
*
299299
* @return The scale of the `fixed_point` number
300300
*/
301-
CUDF_HOST_DEVICE inline scale_type scale() const { return _scale; }
301+
CUDF_HOST_DEVICE [[nodiscard]] inline scale_type scale() const { return _scale; }
302302

303303
/**
304304
* @brief Explicit conversion operator to `bool`
@@ -573,7 +573,7 @@ class fixed_point {
573573
* @param scale The `scale` of the returned `fixed_point` number
574574
* @return `fixed_point` number with a new `scale`
575575
*/
576-
CUDF_HOST_DEVICE inline fixed_point<Rep, Rad> rescaled(scale_type scale) const
576+
CUDF_HOST_DEVICE [[nodiscard]] inline fixed_point<Rep, Rad> rescaled(scale_type scale) const
577577
{
578578
if (scale == _scale) { return *this; }
579579
Rep const value = detail::shift<Rep, Rad>(_value, scale_type{scale - _scale});

0 commit comments

Comments
 (0)