Skip to content

bind() them all (not)#3106

Merged
v4hn merged 11 commits intomoveit:masterfrom
v4hn:pr-master-bind-them-all
Apr 2, 2022
Merged

bind() them all (not)#3106
v4hn merged 11 commits intomoveit:masterfrom
v4hn:pr-master-bind-them-all

Conversation

@v4hn
Copy link
Contributor

@v4hn v4hn commented Mar 31, 2022

Fixes #2766. Replaces #2972 .

@Abishalini will hate me for this changeset for its ease of porting to moveit2... 😢
But it was overdue, I managed to do it over a few evenings and I believe it makes the code much more readable.

This PR should get some priority because patches are quite likely to generate conflicts with this due to its size.
I split all non-trivial changes into separate commits with one huge commit in the end addressing all "trivial" (up to identifier naming) cases. During this work I found and reworked a number of internal details, often related to pointer-use where object lifetime was known or APIs that could be reworked with the flexibility of lambdas.

Eventually I added the clang-tidy check that Robert found. It's important to point out that the provided patch will usually work, but ends up with horrible overhead per parameter/capture and no useful identifiers. So users cannot just apply the patch. But then again, nobody will contribute new code that still uses bind() anyway... Is what you would hope.

@tylerjw @rhaschke

@codecov
Copy link

codecov bot commented Apr 1, 2022

Codecov Report

Merging #3106 (d879aab) into master (5398531) will decrease coverage by 0.06%.
The diff coverage is 57.63%.

❗ Current head d879aab differs from pull request most recent head 9e3d71b. Consider uploading reports for the commit 9e3d71b to get more accurate results

@@            Coverage Diff             @@
##           master    #3106      +/-   ##
==========================================
- Coverage   61.62%   61.57%   -0.05%     
==========================================
  Files         376      376              
  Lines       33275    33310      +35     
==========================================
+ Hits        20504    20508       +4     
- Misses      12771    12802      +31     
Impacted Files Coverage Δ
..._core/collision_detection/src/collision_matrix.cpp 44.04% <0.00%> (ø)
...sion_distance_field/collision_env_distance_field.h 9.10% <ø> (ø)
...e/moveit/ompl_interface/planning_context_manager.h 100.00% <ø> (ø)
.../ompl_interface/src/detail/constraints_library.cpp 1.31% <0.00%> (-0.01%) ⬇️
...z_industrial_motion_planner_testutils/async_test.h 76.00% <ø> (ø)
...ult_capabilities/kinematics_service_capability.cpp 8.09% <0.00%> (ø)
...ccupancy_map_monitor/src/occupancy_map_monitor.cpp 28.75% <0.00%> (-0.88%) ⬇️
...ion/include/moveit/plan_execution/plan_execution.h 81.82% <ø> (ø)
...anning_scene_monitor/src/current_state_monitor.cpp 51.45% <0.00%> (ø)
.../planning_scene_monitor/src/trajectory_monitor.cpp 31.38% <0.00%> (ø)
... and 46 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5398531...9e3d71b. Read the comment docs.

@v4hn v4hn force-pushed the pr-master-bind-them-all branch from 269f01e to edac397 Compare April 1, 2022 09:13
Copy link
Contributor

@rhaschke rhaschke left a comment

Choose a reason for hiding this comment

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

Thanks a lot for all this cleanup work. I like all the changes.
However, in a few locations you also changed public API (changing pointer arguments to references to indicate that valid instances are expected.)
I'm fine with these changes as well, but I'm surprised to see them proposed from you. Don't you argue against public API changes usually?

I guess you already noticed that several tests are broken now.

{
// boost bind is not happy with overloading, so we add intermediate function objects

bool callAdapter1(const PlanningRequestAdapter* adapter, const planning_interface::PlannerManagerPtr& planner,
Copy link
Contributor

Choose a reason for hiding this comment

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

Great cleanup!

const int TRIALS = 1000;
const int THREADS = 2;

bool runCollisionDetection(unsigned int /*id*/, unsigned int trials, const planning_scene::PlanningScene* scene,
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for cleaning up this kind of pointer usage!

@rhaschke
Copy link
Contributor

rhaschke commented Apr 1, 2022

I shortly looked into the first failing test and it is very strange: The ModelBasedStateSpaceFactoryPtr returned from factory_selector:
https://github.com/ros-planning/moveit/blob/779b7c8b019f70898d4de3189f9261c9697d9b9f/moveit_planners/ompl/ompl_interface/src/planning_context_manager.cpp#L316
is NULL although the actually called function returns a valid pointer. Hence, somewhere in the hierarchy of calling this std::function, the return value is screwed! Looks like a gcc or libstdc++ bug.

v4hn added 2 commits April 1, 2022 13:48
the trailing 1 and 2 and bind() usage made this harder to parse than it has to be.

Technically this breaks API (the methods are protected, not private).
But if you are that far into the code base to inherit here and rely on the names
of these simple methods, you probably agree that this improves readability.
@v4hn v4hn force-pushed the pr-master-bind-them-all branch from 04eea20 to 681bc2b Compare April 1, 2022 11:52
@v4hn
Copy link
Contributor Author

v4hn commented Apr 1, 2022

Thanks for the additional patches! I rebased for a clean history. Yes, I saw the failing tests already, but just finished the patch yesterday and wanted to push it already. I just started to look into it a bit further as well, but could not understand it right away.

I shortly looked into the first failing test and it is very strange: The ModelBasedStateSpaceFactoryPtr returned from factory_selector:

Messy. I see the same issue with clang 13 (did not get to upgrade to 14 yet), so I'm not sure it's a compiler issue. We probably need to find a workaround whether or not we can pinpoint an external bug.
That part of the API is insane anyway. Why pass a function to a method just to call it first thing and ignore it after that...

Speaking about API: All the header-specific changes I made address private (and in one case protected) methods. the mesh helper might be debatable (see my commit message), but I do not consider the rest to be public API.

@rhaschke
Copy link
Contributor

rhaschke commented Apr 1, 2022

I see the same issue with clang 13 (did not get to upgrade to 14 yet), so I'm not sure it's a compiler issue. We probably need to find a workaround whether or not we can pinpoint an external bug. That part of the API is insane anyway. Why pass a function to a method just to call it first thing and ignore it after that...

Yes, probably it is a bug in libstdc++. At some point in the call hierarchy the returned shared_ptr reference is copied (which is wrong in first place) and then released.

Speaking about API: All the header-specific changes I made address private (and in one case protected) methods. the mesh helper might be debatable (see my commit message), but I do not consider the rest to be public API.

Sorry, I was convinced to have seen a public declaration. Checking again, you are right, everything is private or protected.

@rhaschke
Copy link
Contributor

rhaschke commented Apr 1, 2022

That part of the API is insane anyway. Why pass a function to a method just to call it first thing and ignore it after that...

You are right, I didn't noticed this before. I suggested two approaches to fix the issue in v4hn#3 - both changing protected API of OMPL::PlanningContextManager, which is fine I think. Given your comment, I prefer the last one.

@v4hn
Copy link
Contributor Author

v4hn commented Apr 1, 2022

Makes sense. I cherry-picked your proposed modification of the protected getPlanningContext method. 👍

@rhaschke
Copy link
Contributor

rhaschke commented Apr 1, 2022

Sorry, I forgot to remove the unused req argument at caller side... The PR was meant to be tested by GHA before merging ;-)

@rhaschke
Copy link
Contributor

rhaschke commented Apr 1, 2022

Closing and reopening to trigger CI...

@rhaschke rhaschke closed this Apr 1, 2022
@rhaschke rhaschke reopened this Apr 1, 2022
@rhaschke
Copy link
Contributor

rhaschke commented Apr 1, 2022

I tried to reproduce the shared_ptr issue in a minimal example, but there it works: https://godbolt.org/z/T68jzMYW4.

@rhaschke
Copy link
Contributor

rhaschke commented Apr 2, 2022

@v4hn, I think this is ready to merge after squash-merging the fixups.

v4hn and others added 6 commits April 2, 2022 22:48
It made the code hard to understand in many places and was needed because
lambdas did not exist when this was written. Times change.
to ensure people use lambdas. Look anywhere. That's what you should do.
... to improve readability
- Calling the factory_selector lambda causes the returned value to be NULL.
  There is no value in having this selector function. We could directly pass the correct factory.
- MotionPlanRequest isn't actually used.
@v4hn v4hn force-pushed the pr-master-bind-them-all branch from d879aab to 9e3d71b Compare April 2, 2022 20:56
@v4hn
Copy link
Contributor Author

v4hn commented Apr 2, 2022

I think this is ready to merge after squash-merging the fixups.

Thank you for spending the time to find my superfluous ampersand that broke the patch... 🏅
I integrated the fixes and will merge.

@v4hn v4hn merged commit cce0ffe into moveit:master Apr 2, 2022
henningkayser added a commit to moveit/moveit2 that referenced this pull request May 10, 2022
rhaschke added a commit to ubi-agni/moveit that referenced this pull request Nov 22, 2022
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.

avoid boost/std::bind

2 participants