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

Iox #391 static memory alternative for std function #473

Conversation

MatthiasKillat
Copy link
Contributor

@MatthiasKillat MatthiasKillat commented Jan 2, 2021

Pre-Review Checklist for the PR Author

  1. Branch follows the naming format (iox-#123-this-is-a-branch)
  2. Commits messages are according to this guideline
    • Commit messages have the issue ID (iox-#123 commit text)
    • Commit messages are signed (git commit -s)
    • Commit author matches Eclipse Contributor Agreement (and ECA is signed)
  3. Update the PR title
    • Follow the same conventions as for commit messages
    • Link to the relevant issue
  4. Relevant issues are linked
  5. Add sensible notes for the reviewer
  6. All checks have passed
  7. Assign PR to reviewer

Notes for Reviewer

Checklist for the PR Reviewer

  • Commits are properly organized and messages are according to the guideline
  • Code according to our coding style and naming conventions
  • Unit tests have been written for new behavior
  • Public API changes are documented via doxygen
  • Copyright owner are updated in the changed files
  • PR title describes the changes

Post-review Checklist for the PR Author

  1. All open points are addressed and tracked via issues

Post-review Checklist for the Eclipse Committer

  1. All checkboxes in the PR checklist are checked or crossed out
  2. Merge

References

Summary

Added a static storage alternative for std::function including tests. This is supposed to store any callable up to a given storage size. As is also the case for sd::function, it cannot e used in shared memory (this cannot be avoided due to the fact that pointers to e.g. free functions but also lambdas are stored which will usually not be valid in another process).

The implementation uses cxx::function_ref, otherwise parts of those functionality would have been rewritten/duplicated. It is important to note that much of the complications arise due to the fact that information about the underlying stored type is lost but it still must be ensured that it is copied/moved properly (according to RAII). Naturally these problems do NOT arise when only a reference is stored (as in function_ref).

Fixed an issue that function_ref was not constructible from function pointers of free functions (only function names, but those are not function pointers but are converted to them). There is still an open point of a conversion from something potentially not convertible to a void pointer in the function_ref ctor (existed before as well, as it would take a universal reference to anything callable). For function_pointers this is compliant with the POSIX standard, but in general it is not (function pointers cannot be converted to void pointers in general).

This requires some further investigation. A potential fix could be added here as well.

Signed-off-by: Matthias Killat <matthias.killat@apex.ai>
… bug

Signed-off-by: Matthias Killat <matthias.killat@apex.ai>
… pointer

Signed-off-by: Matthias Killat <matthias.killat@apex.ai>
Signed-off-by: Matthias Killat <matthias.killat@apex.ai>
Signed-off-by: Matthias Killat <matthias.killat@apex.ai>
Signed-off-by: Matthias Killat <matthias.killat@apex.ai>
Signed-off-by: Matthias Killat <matthias.killat@apex.ai>
Signed-off-by: Matthias Killat <matthias.killat@apex.ai>
Signed-off-by: Matthias Killat <matthias.killat@apex.ai>
Signed-off-by: Matthias Killat <matthias.killat@apex.ai>
Signed-off-by: Matthias Killat <matthias.killat@apex.ai>
Signed-off-by: Matthias Killat <matthias.killat@apex.ai>
@MatthiasKillat MatthiasKillat added the enhancement New feature label Jan 2, 2021
Signed-off-by: Matthias Killat <matthias.killat@apex.ai>
Copy link
Contributor

@mossmaurice mossmaurice left a comment

Choose a reason for hiding this comment

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

Only reviewed function_ref and type_trait changes so far.

Signed-off-by: Matthias Killat <matthias.killat@apex.ai>
orecham
orecham previously requested changes Jan 4, 2021
{
namespace cxx
{
/// @note set the storage type and reorder template arguments for the user API
Copy link
Contributor

Choose a reason for hiding this comment

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

Some punctuation would help with readability.

iceoryx_utils/include/iceoryx_utils/cxx/function.hpp Outdated Show resolved Hide resolved
iceoryx_utils/include/iceoryx_utils/cxx/type_traits.hpp Outdated Show resolved Hide resolved
@orecham
Copy link
Contributor

orecham commented Jan 4, 2021

Idea looks sound to me. Just needs some documentation !

@MatthiasKillat
Copy link
Contributor Author

MatthiasKillat commented Jan 4, 2021

@ithier. I will improve the documentation. I prefer brief docu though, unless the use cases are very tricky. No one reads long docu for functions or classes. :-)

Copy link
Contributor

@mossmaurice mossmaurice left a comment

Choose a reason for hiding this comment

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

Great work! Tests are not yet reviewed.

  1. Please check if the implementation of storable_function can be simplified by using one generic c'tor, as in std::function:
template< class F, class Alloc >
function( std::allocator_arg_t, const Alloc& alloc, F f );
  1. Align cxx::PoorMansHeap usage

@MatthiasKillat
Copy link
Contributor Author

I will update the PR in a day or two, until then no further review needed.

…rable

Signed-off-by: Matthias Killat <matthias.killat@apex.ai>
Signed-off-by: Matthias Killat <matthias.killat@apex.ai>
@MatthiasKillat
Copy link
Contributor Author

Reworked, can be reviewed now.

Signed-off-by: Matthias Killat <matthias.killat@apex.ai>
Copy link
Contributor

@elfenpiff elfenpiff left a comment

Choose a reason for hiding this comment

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

Only partially reviewed I will continue on monday.

Please adjust all copyright headers.

Signed-off-by: Matthias Killat <matthias.killat@apex.ai>
Signed-off-by: Matthias Killat <matthias.killat@apex.ai>
@MatthiasKillat
Copy link
Contributor Author

MatthiasKillat commented May 27, 2021

The pipeline reports a problem with alignof that is used in a non-standard way - applied to expressions (gcc allows this). I have changed this to be semantically equivalent for our case...

Also needed to remove a test for the static storage which essentially checked that deallocation does not actually clear the storage but to do so caused an uninitialized read warning (unavoidable in this case I think). Test removed since this is no real requirement for functionality, just an aspect of optimization (i.e. not setting the memory to zero as most allocators do).

@MatthiasKillat MatthiasKillat dismissed orecham’s stale review May 28, 2021 13:24

Stale review, changed quite a bit and addressed all points.

@MatthiasKillat
Copy link
Contributor Author

MatthiasKillat commented Jun 1, 2021

@elfenpiff @mossmaurice I think I addressed all the points and the CI is green.

It is by no means perfect, but I think it is mature enough to be tried out internally. Should there be any further issues I will find them when I replace internal std::function occurrences next. Usage should be fine (according to tests), within the limitations of the capacity constraint and behavior of operator() which should be as std::function.

@mossmaurice
Copy link
Contributor

@elfenpiff @mossmaurice I think I addressed all the points and the CI is green.

It is by no means perfect, but I think it is mature enough to be tried out internally. Should there be any further issues I will find them when I replace internal std::function occurrences next. Usage should be fine (according to tests), within the limitations of the capacity constraint and behavior of operator() which should be as std::function.

👍 I'll finish off the review tonight.

Could you merge origin/master to this branch? There are still some conflicts.

Signed-off-by: Matthias Killat <matthias.killat@apex.ai>
@MatthiasKillat MatthiasKillat force-pushed the iox-#391-static-memory-alternative-for-std-function branch from b98e88f to a4c4971 Compare June 1, 2021 15:00
elfenpiff
elfenpiff previously approved these changes Jun 2, 2021
Copy link
Contributor

@mossmaurice mossmaurice left a comment

Choose a reason for hiding this comment

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

10/13 done

Copy link
Contributor

@mossmaurice mossmaurice left a comment

Choose a reason for hiding this comment

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

LGTM in general, only minor findings. Let's get this merged!

@mossmaurice
Copy link
Contributor

mossmaurice commented Jun 2, 2021

Another thing that just popped up: As this PR introduced a lot of new code, could you run Axivion with these coding rules over this PR (soon it will run with every PR)?

@MatthiasKillat
Copy link
Contributor Author

No, in my opinion we will introduce Axivion for the whole code base and from then on we will run it for every PR. I have no license for it yet and do not see that we should block the PR due to this. I will fix any problem occurring due to this in a new PR, but we should introduce Axivion properly before this is done.

elfenpiff
elfenpiff previously approved these changes Jun 2, 2021
@MatthiasKillat MatthiasKillat force-pushed the iox-#391-static-memory-alternative-for-std-function branch 2 times, most recently from 60ef050 to a4c4971 Compare June 2, 2021 11:42
Signed-off-by: Matthias Killat <matthias.killat@apex.ai>
@MatthiasKillat
Copy link
Contributor Author

Now it should be ok if the CI builds, wanted to get rid off one merge commit at least hence the force pushes.

@mossmaurice
Copy link
Contributor

I will fix any problem occurring due to this in a new PR, but we should introduce Axivion properly before this is done.

Could you create an issue for that? Axivion was introduced in #409 for the master branch, but currently lacks a script for the local scan.

@MatthiasKillat
Copy link
Contributor Author

Before we create any issue we should wait whether anything pops up at all.

@MatthiasKillat
Copy link
Contributor Author

@elfenpiff @mossmaurice should be ready to merge

@dkroenke dkroenke self-requested a review June 4, 2021 08:48
@MatthiasKillat MatthiasKillat merged commit f99e0c3 into eclipse-iceoryx:master Jun 4, 2021
@MatthiasKillat MatthiasKillat deleted the iox-#391-static-memory-alternative-for-std-function branch June 4, 2021 08:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

static memory alternative for std::function
6 participants