New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clang tidy #2982
Clang tidy #2982
Conversation
hpx/parallel/algorithms/for_loop.hpp
Outdated
return util::partitioner<ExPolicy>::call_with_index( | ||
policy, first, size, stride, | ||
part_iterations<F, S, args_type>{ | ||
std::forward<F>(f), stride, std::move(args) | ||
std::forward<F>(f), stride, args | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAICS, this code causes the data to be copied twice. Once when creating args
and once while calling call_with_index
. Is there any way to avoid that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's a potential problem indeed. I don't know how to avoid that. args
is needed twice, once for part_iterations
and then in the finalizer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't args_type
be a tuple of references instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, they need to decay-copied at least once to stay in scope long enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, so let's copy them once and not thrice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't know how...
The first one, is forwarding the arguments into a local tuple, which then needs to be passed to the iteration function and the exit function, which both need a copy of the arguments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, the exit function is guaranteed to outlive everything else, right? So why not hold the copy there and let the iteration refer to those copies? Would that work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, this would require some significant refactoring of the partitioner. I would prefer doing that in another PR though, but I guess it would work in principle
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, the issue of having multiple copies should be fixed with the latest commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect, thanks!
@@ -75,6 +75,7 @@ namespace hpx { namespace agas { namespace server | |||
addr.address_ = g.lva(); | |||
} | |||
|
|||
naming::id_type source = p.source_id(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the rationale of this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
p
is moved here: https://github.com/STEllAR-GROUP/hpx/pull/2982/files/69463c83e47825205fbb10147b2d97b6726e1242#diff-fe4bb9d1c3c7a064a0b4dd4bdae63198L87
That means that the source_id
used later on to update the cache entry is being used from a moved from object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, thanks for catching this.
@@ -505,7 +505,6 @@ namespace hpx { namespace resource { namespace detail | |||
affinity_data_.set_num_threads(new_pu_nums.size()); | |||
affinity_data_.set_pu_nums(std::move(new_pu_nums)); | |||
affinity_data_.set_affinity_masks(std::move(new_affinity_masks)); | |||
affinity_data_.init_cached_pu_nums(new_pu_nums.size()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the rationale of this change? is that related to the clang-tidy checks?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, new_pu_nums
was moved a few lines above. When looking at the code of affinity_data
, init_cached_pu_nums
does nothing in this specific case anyway: https://github.com/STEllAR-GROUP/hpx/blob/master/src/runtime/threads/policies/affinity_data.cpp#L324
@@ -286,7 +286,7 @@ namespace hpx { namespace threads | |||
"default", | |||
"low", | |||
"normal", | |||
"high (recursive)" | |||
"high (recursive)", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent catch!
tools/clang-tidy.sh
Outdated
CHECKS="$CHECKS,misc-assert-side-effect" | ||
CHECKS="$CHECKS,misc-dangling-handle" | ||
CHECKS="$CHECKS,misc-move-constructor-init" | ||
CHECKS="$CHECKS,misc-move-forwarding-reference" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two are duplicated.
This PR looks like it should be merged. I will create an Issue to remember the partitioner copy problem and then someone can/should merge this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I have created a seperate issue for the arg copy discussion
- The script now runs more checks. - Fixing diff against master - Fixing script if no bc is available
This patch fixes problems reported by clang-tidy after enabling the following checks: modernize-use-nullptr misc-use-after-move misc-virtual-near-miss misc-multiple-statement-macro misc-move-constructor-init misc-move-forwarding-reference misc-assert-side-effect misc-dangling-handle misc-move-constructor-init misc-move-forwarding-reference misc-non-copyable-objects misc-forwarding-reference-overload
All comments have been addressed. This should be good to go now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
This patch enables the partitioner to accept parameters which are perfect forwarded to the passed iteration functions when used with call_with_index. This properly fixes the for_loop related use-after-move warnings reported by clang-tidy.
Fixes as reported by clang-tidy after enabling the following checks: