Skip to content

Conversation

@stuqdog
Copy link
Member

@stuqdog stuqdog commented Feb 12, 2024

  • No longer disable performance-move-const-arg in clang-tidy.
  • Necessary fixes for clang-tidy to pass.

@stuqdog stuqdog requested a review from a team as a code owner February 12, 2024 16:13
@stuqdog stuqdog requested review from benjirewis and njooma and removed request for a team February 12, 2024 16:13
@stuqdog stuqdog marked this pull request as draft February 12, 2024 16:32
@stuqdog stuqdog marked this pull request as ready for review February 12, 2024 17:05

void DialOptions::set_timeout(std::chrono::duration<float> timeout) {
timeout_ = std::move(timeout);
timeout_ = timeout;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one surprised me. It looks to me like the move was correct?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(per error message) std::chrono::duration<float> is trivially copyable, so the move has no effect.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK I guess. I think it is overzealous. What if the type changed in the future and was no longer trivially copyable? Unlikely, I'll admit, for std::chrono::duration, but not for types we control. I don't see that the move has any downsides.

https://devblogs.microsoft.com/oldnewthing/20220512-00/?p=106651

Overall, I sort of feel like maybe we should disable that particular clang tidy check and just allow moves of trivial types. It is much easier to get SDK developers used to using move consistently if there isn't a gotcha about trivial types.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this makes sense. I've set performance-move-const-arg.CheckTriviallyCopyableMove to false and reinstated the move here, as well as the moves in geometry.cpp

Copy link
Member

@benjirewis benjirewis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM % Drew's comments on non-consting instead of moving.


void DialOptions::set_timeout(std::chrono::duration<float> timeout) {
timeout_ = std::move(timeout);
timeout_ = timeout;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(per error message) std::chrono::duration<float> is trivially copyable, so the move has no effect.

@stuqdog stuqdog requested a review from acmorrow February 13, 2024 14:44
Copy link
Member

@acmorrow acmorrow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM mod a few small things that don't, I think, warrant another round of review. I feel a bit like the warning on move of trivial is overzealous, but I don't feel strongly about it.


void DialOptions::set_timeout(std::chrono::duration<float> timeout) {
timeout_ = std::move(timeout);
timeout_ = timeout;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK I guess. I think it is overzealous. What if the type changed in the future and was no longer trivially copyable? Unlikely, I'll admit, for std::chrono::duration, but not for types we control. I don't see that the move has any downsides.

https://devblogs.microsoft.com/oldnewthing/20220512-00/?p=106651

Overall, I sort of feel like maybe we should disable that particular clang tidy check and just allow moves of trivial types. It is much easier to get SDK developers used to using move consistently if there isn't a gotcha about trivial types.

const std::lock_guard<std::mutex> lock(lock_);
const std::string name = api.to_string() + "/" + model.to_string();
return lookup_model_inlock_(std::move(name), std::move(lock));
return lookup_model_inlock_(name, std::move(lock));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need the move on lock either? It's const.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, nope! Surprised it let us keep that. Fixed.

this->short_names_ = new_short_names;

for (const auto& resource : resources) {
for (auto resource : resources) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree with this one, looking at it. This works because it now copies the pair out, and then moves from it. That doesn't seem worthwhile vs just viewing the pair and copying the second in the call to do_add

}

void ResourceManager::do_add(const Name& name, const std::shared_ptr<Resource>& resource) {
void ResourceManager::do_add(Name name, std::shared_ptr<Resource> resource) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be Name const& name, std::shared_ptr<Resource> resource) because the first parameter is only observed, but the second one is actually moved.

@stuqdog stuqdog merged commit ad64b76 into viamrobotics:main Feb 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants