Skip to content
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

Group message initializations by their appropriate checks #350

Merged
merged 5 commits into from
Apr 15, 2019

Conversation

allenh1
Copy link
Contributor

@allenh1 allenh1 commented Feb 22, 2019

I was going through message generation, and found that there were several redundant checks on message initialization.

This clears it up.


This change is Reviewable

@allenh1 allenh1 added bug Something isn't working enhancement New feature or request in review Waiting for review (Kanban column) labels Feb 22, 2019
@allenh1 allenh1 self-assigned this Feb 22, 2019
@allenh1 allenh1 requested a review from clalancette February 22, 2019 17:10
@dirk-thomas
Copy link
Member

This patch will conflict with #334. Please rebase / update this patch once the referenced PR has been merged.

@dirk-thomas dirk-thomas added in progress Actively being worked on (Kanban column) requires-changes and removed in review Waiting for review (Kanban column) bug Something isn't working labels Feb 22, 2019
@allenh1
Copy link
Contributor Author

allenh1 commented Feb 22, 2019

@dirk-thomas you got it!

@allenh1 allenh1 force-pushed the reduce-redundant-if-statements branch from 5ef642d to b1099c7 Compare March 12, 2019 20:30
@allenh1
Copy link
Contributor Author

allenh1 commented Mar 13, 2019

@dirk-thomas rebased & ready

@dirk-thomas dirk-thomas added in review Waiting for review (Kanban column) and removed in progress Actively being worked on (Kanban column) requires-changes labels Mar 13, 2019
@dirk-thomas
Copy link
Member

The patch seems to change the initialization order of the members, no? If yes, the members should be initialized in the order they are defined in.

@allenh1
Copy link
Contributor Author

allenh1 commented Mar 13, 2019

The patch seems to change the initialization order of the members, no?

@dirk-thomas I don't think the order is changed (at least it shouldn't be). The goal here was to collapse the if checks into a single if check. To clarify what this patch does, I probably should have attached a diff for you...

Here's a diff of the generated primitives_static__struct.hpp files (where the /g/primitives_static__struct.hpp_old is before this patch is applied).

]--- /g/primitives_static__struct.hpp_old       2019-03-13 12:31:14.580896800 -0400
+++ /g/primitives_static__struct.hpp    2019-03-13 12:32:23.262555200 -0400
@@ -48,49 +48,17 @@
       rosidl_generator_cpp::MessageInitialization::ZERO == _init)
     {
       this->bool_value = false;
-    }
-    if (rosidl_generator_cpp::MessageInitialization::ALL == _init ||
-      rosidl_generator_cpp::MessageInitialization::ZERO == _init)
-    {
       this->byte_value = 0;
       this->char_value = 0;
-    }
-    if (rosidl_generator_cpp::MessageInitialization::ALL == _init ||
-      rosidl_generator_cpp::MessageInitialization::ZERO == _init)
-    {
       this->float32_value = 0.0f;
-    }
-    if (rosidl_generator_cpp::MessageInitialization::ALL == _init ||
-      rosidl_generator_cpp::MessageInitialization::ZERO == _init)
-    {
       this->float64_value = 0.0;
-    }
-    if (rosidl_generator_cpp::MessageInitialization::ALL == _init ||
-      rosidl_generator_cpp::MessageInitialization::ZERO == _init)
-    {
       this->int8_value = 0;
       this->uint8_value = 0;
       this->int16_value = 0;
       this->uint16_value = 0;
-    }
-    if (rosidl_generator_cpp::MessageInitialization::ALL == _init ||
-      rosidl_generator_cpp::MessageInitialization::ZERO == _init)
-    {
       this->int32_value = 0l;
-    }
-    if (rosidl_generator_cpp::MessageInitialization::ALL == _init ||
-      rosidl_generator_cpp::MessageInitialization::ZERO == _init)
-    {
       this->uint32_value = 0ul;
-    }
-    if (rosidl_generator_cpp::MessageInitialization::ALL == _init ||
-      rosidl_generator_cpp::MessageInitialization::ZERO == _init)
-    {
       this->int64_value = 0ll;
-    }
-    if (rosidl_generator_cpp::MessageInitialization::ALL == _init ||
-      rosidl_generator_cpp::MessageInitialization::ZERO == _init)
-    {
       this->uint64_value = 0ull;
     }
   }
@@ -102,49 +70,17 @@
       rosidl_generator_cpp::MessageInitialization::ZERO == _init)
     {
       this->bool_value = false;
-    }
-    if (rosidl_generator_cpp::MessageInitialization::ALL == _init ||
-      rosidl_generator_cpp::MessageInitialization::ZERO == _init)
-    {
       this->byte_value = 0;
       this->char_value = 0;
-    }
-    if (rosidl_generator_cpp::MessageInitialization::ALL == _init ||
-      rosidl_generator_cpp::MessageInitialization::ZERO == _init)
-    {
       this->float32_value = 0.0f;
-    }
-    if (rosidl_generator_cpp::MessageInitialization::ALL == _init ||
-      rosidl_generator_cpp::MessageInitialization::ZERO == _init)
-    {
       this->float64_value = 0.0;
-    }
-    if (rosidl_generator_cpp::MessageInitialization::ALL == _init ||
-      rosidl_generator_cpp::MessageInitialization::ZERO == _init)
-    {
       this->int8_value = 0;
       this->uint8_value = 0;
       this->int16_value = 0;
       this->uint16_value = 0;
-    }
-    if (rosidl_generator_cpp::MessageInitialization::ALL == _init ||
-      rosidl_generator_cpp::MessageInitialization::ZERO == _init)
-    {
       this->int32_value = 0l;
-    }
-    if (rosidl_generator_cpp::MessageInitialization::ALL == _init ||
-      rosidl_generator_cpp::MessageInitialization::ZERO == _init)
-    {
       this->uint32_value = 0ul;
-    }
-    if (rosidl_generator_cpp::MessageInitialization::ALL == _init ||
-      rosidl_generator_cpp::MessageInitialization::ZERO == _init)
-    {
       this->int64_value = 0ll;
-    }
-    if (rosidl_generator_cpp::MessageInitialization::ALL == _init ||
-      rosidl_generator_cpp::MessageInitialization::ZERO == _init)
-    {
       this->uint64_value = 0ull;
     }
   }

Since this is strictly removing, it does not appear to permute the order (although this is a rather trivial case).

The two originals are in a gist here.

Let me know if you want to see any specific files.

@allenh1 allenh1 requested a review from dirk-thomas March 13, 2019 16:46
@dirk-thomas
Copy link
Member

Can you please try it with a message file which has a mixture of fields - some with default values, some without - and share the diff for that. Thanks.

@allenh1
Copy link
Contributor Author

allenh1 commented Mar 13, 2019

Can you please try it with a message file which has a mixture of fields - some with default values, some without - and share the diff for that. Thanks.

Do you have a particular file in mind?

@dirk-thomas
Copy link
Member

Do you have a particular file in mind?

No, not really. I would just expect that case to have a changed order.

@allenh1
Copy link
Contributor Author

allenh1 commented Mar 13, 2019

@dirk-thomas yeah, that makes sense. I just ran colcon test on the package and have some more work to do, it seems.

I looking at various__struct.hpp, the diff gets a bit ugly. Here's the two files.

I'll move this back to in progress and work on it a little later. Sorry for the noise.

@allenh1 allenh1 added in progress Actively being worked on (Kanban column) and removed in review Waiting for review (Kanban column) labels Mar 13, 2019
@allenh1 allenh1 force-pushed the reduce-redundant-if-statements branch from 46ed046 to f925ee7 Compare March 17, 2019 02:34
@allenh1 allenh1 force-pushed the reduce-redundant-if-statements branch 2 times, most recently from a43c67b to 026167b Compare March 31, 2019 15:51
@allenh1
Copy link
Contributor Author

allenh1 commented Mar 31, 2019

Okay, @dirk-thomas I got all the tests passing and updated the gist I linked to. Here's the diff for various__struct.hpp. To me, it looks like the order of initialization has remained in-tact, and the only additions were just relocated removals from above.

Could you run CI on this for me please? Apparently I can't do that anymore (unless the way to do it has changed).

@allenh1 allenh1 added the in review Waiting for review (Kanban column) label Mar 31, 2019
@allenh1 allenh1 removed the in progress Actively being worked on (Kanban column) label Mar 31, 2019
@allenh1
Copy link
Contributor Author

allenh1 commented Apr 5, 2019

@mikaelarguedas you might also be a good person to look at this. Let me know if this needs any changes.

Attention was drawn to this by PVS studio, if anyone was curious.

@allenh1 allenh1 force-pushed the reduce-redundant-if-statements branch from bcae336 to 79fb77e Compare April 7, 2019 18:04
@allenh1
Copy link
Contributor Author

allenh1 commented Apr 7, 2019

@dirk-thomas thanks for the review -- ready for another round!

@allenh1 allenh1 requested a review from dirk-thomas April 11, 2019 21:11
@(line)
@[ end for]@
@[ end for]@
Copy link
Member

Choose a reason for hiding this comment

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

Indentation of this block is off.

@dirk-thomas
Copy link
Member

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@allenh1 allenh1 force-pushed the reduce-redundant-if-statements branch from 3a8be19 to d94e7c1 Compare April 15, 2019 17:34
@allenh1
Copy link
Contributor Author

allenh1 commented Apr 15, 2019

Okay, I'm decently sure I've got the indentation in there correctly now (sorry about that -- can be a bit confusing).

As for the CI problems, those are seemingly unrelated, as far as I can tell. I rebased on top of the current rosidl master in case that might have been the problem (though I doubt it since there was only one extra commit).

@dirk-thomas What should I look at in order to rule out these failures?

@dirk-thomas
Copy link
Member

The failing tests on CI are unfortunately known to be flaky.

Another round after the latest updates just to be sure:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@dirk-thomas
Copy link
Member

Thanks for the patch and for iterating on it.

@dirk-thomas dirk-thomas merged commit 3054404 into master Apr 15, 2019
@delete-merged-branch delete-merged-branch bot deleted the reduce-redundant-if-statements branch April 15, 2019 20:05
@dirk-thomas dirk-thomas removed the in review Waiting for review (Kanban column) label Apr 15, 2019
@allenh1
Copy link
Contributor Author

allenh1 commented Apr 15, 2019

@dirk-thomas my pleasure, as always. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants