-
Notifications
You must be signed in to change notification settings - Fork 403
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-#2052 Implement move/copy constructor and assignment for FixedPositionContainer
#2069
iox-#2052 Implement move/copy constructor and assignment for FixedPositionContainer
#2069
Conversation
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.
Feel free to add yourself as copyright holder to the files with significant changes :)
iceoryx_dust/container/include/iox/detail/fixed_position_container.inl
Outdated
Show resolved
Hide resolved
iceoryx_dust/container/include/iox/detail/fixed_position_container.inl
Outdated
Show resolved
Hide resolved
iceoryx_dust/container/include/iox/detail/fixed_position_container.inl
Outdated
Show resolved
Hide resolved
iceoryx_dust/container/include/iox/detail/fixed_position_container.inl
Outdated
Show resolved
Hide resolved
iceoryx_dust/container/include/iox/detail/fixed_position_container.inl
Outdated
Show resolved
Hide resolved
iceoryx_dust/test/moduletests/test_container_fixed_position_container.cpp
Show resolved
Hide resolved
iceoryx_dust/test/moduletests/test_container_fixed_position_container.cpp
Outdated
Show resolved
Hide resolved
iceoryx_dust/test/moduletests/test_container_fixed_position_container.cpp
Show resolved
Hide resolved
iceoryx_dust/test/moduletests/test_container_fixed_position_container.cpp
Show resolved
Hide resolved
iceoryx_dust/test/moduletests/test_container_fixed_position_container.cpp
Show resolved
Hide resolved
Codecov Report
@@ Coverage Diff @@
## master #2069 +/- ##
==========================================
+ Coverage 80.04% 80.18% +0.13%
==========================================
Files 417 418 +1
Lines 16055 16113 +58
Branches 2255 2265 +10
==========================================
+ Hits 12852 12920 +68
+ Misses 2398 2385 -13
- Partials 805 808 +3
Flags with carried forward coverage won't be shown. Click here to find out more.
|
39a9c46
to
b0929dd
Compare
iceoryx_dust/container/include/iox/detail/fixed_position_container.inl
Outdated
Show resolved
Hide resolved
iceoryx_dust/container/include/iox/detail/fixed_position_container.inl
Outdated
Show resolved
Hide resolved
iceoryx_dust/container/include/iox/detail/fixed_position_container.inl
Outdated
Show resolved
Hide resolved
iceoryx_dust/container/include/iox/detail/fixed_position_container.inl
Outdated
Show resolved
Hide resolved
iceoryx_dust/container/include/iox/detail/fixed_position_container.inl
Outdated
Show resolved
Hide resolved
iceoryx_dust/container/include/iox/fixed_position_container.hpp
Outdated
Show resolved
Hide resolved
I found a weird behavior when using git. I noticed that using # Track test.txt
git add test.txt
git commit -s
# Modify separate parts of test.txt, denoted as A and B
git add -p test.txt # Use y and n (add A and ignore B)
git commit -s
# Both A and B are included in the last commit (though only A was supposed to be included)
git status So far, I've been using |
Signed-off-by: Dennis Liu <[email protected]> Based on the discussion at [eclipse-iceoryx#2069 (comment)], additional tests have been incorporated. Furthermore, some statistical results have been updated due to modifications in the `copy_and_move_impl`. For instance, when a non-empty container is moved to an empty container using the move assignment, the `MoveCtor` is the function that is invoked, not the `operator=`. This is because if the slot was previously free, we utilize placement new to ensure proper functionality. Consequently, it is the `MoveCtor` that gets called."
The test ran on the Linux platform (Ubuntu 22.04 LTS via WSL) for both C++14 and C++17 with g++11. |
@Dennis40816 I don't use Could you please rebase to master and fix the conflict in the files. I try to start reviewing tomorrow. |
75a4afa
to
f825c96
Compare
Signed-off-by: Dennis Liu <[email protected]> Based on the discussion at [eclipse-iceoryx#2069 (comment)], additional tests have been incorporated. Furthermore, some statistical results have been updated due to modifications in the `copy_and_move_impl`. For instance, when a non-empty container is moved to an empty container using the move assignment, the `MoveCtor` is the function that is invoked, not the `operator=`. This is because if the slot was previously free, we utilize placement new to ensure proper functionality. Consequently, it is the `MoveCtor` that gets called."
With the latest merge it seems there is another merge conflict. Please update again. It also seems that the gcc builds are broken. I guess you need to move the specialization to the .inl file |
Ok, I'll switch to g++ 8.4.0 and take a took what's going on. |
Signed-off-by: Dennis Liu <[email protected]> The `FixedPositionContainer` was enhanced with copy and move constructors as well as assignment operations. For both copy and move operations, member variables like `m_size`, `m_begin_free`, `m_begin_used`, `m_status`, and `m_next` are handled using copy assignments. The primary distinction between copy and move is in how `m_data` is handled. Specifically, after a move operation: - The original container's `m_size`, `m_begin_free`, and `m_begin_used` are reset. - However, `m_data`, `m_status`, and `m_next` of the original container remain unchanged. Header declarations have been updated to align with these modifications.
Signed-off-by: Dennis Liu <[email protected]> Added unit tests to validate both copy and move semantics for the `FixedPositionContainer`. Run `dust/test/dust_moduletests` to view result.
Signed-off-by: Dennis Liu <[email protected]> Refactor the copy and move constructors of FixedPositionContainer to leverage the functionality of the respective assignment operators. This reduces code duplication and ensures consistent behavior across constructors and assignment operations. Update tests to reflect the changes in behavior.
Signed-off-by: Dennis Liu <[email protected]> The changes involved renaming the tests and ensuring the test content better aligns with the ZOMBIE criteria. The primary object under test is `SutComplex`. For each constructor or assignment, tests were conducted on empty containers, single element containers, multiple elements containers, and full capacity containers. In the case of moves, additional checks were made to see if the `DTor` of `SutComplex` was called (from `FixedPositionContainer::clear()`).
Signed-off-by: Dennis Liu <[email protected]> Add issue 2052 into unreleased document in feature section.
Signed-off-by: Dennis Liu <[email protected]> Fix nitpick mentioned in PR. Including: - Replace index value `0U` by `IndexType::First`. - Change variable to snake_case.
Signed-off-by: Dennis Liu <[email protected]> Add more strict check(e.g., check full, size, empty) and rearrange the test code.
Signed-off-by: Dennis Liu <[email protected]> Fix typo in test case b46d0be7-5977-467e-adc4-2e9adc554fdd. The result should be true.
Signed-off-by: Dennis Liu <[email protected]> According to PR discussion, I used the latter method to implement both ctor and assignment.
Signed-off-by: Dennis Liu <[email protected]> Add a private function init() to reduce code duplication. Also, fix the issues mentioned after commit `b0929dd96287f46d519c634522f2700d0a646221`.
Signed-off-by: Dennis Liu <[email protected]> We use same test data(e.g., {0U, 1U, 2U, 3U} or `fillSut()` or `fillSutComplex()` function in two consecutive tests) in `FixPositionContainer` ctor or assignment related tests. {56U, 57U, 58U, 59U} replace {0U, 1U, 2U, 3U} in multiple values tests.
Signed-off-by: Dennis Liu <[email protected]> Rename `init` to `copy_and_move_impl` to clear the function purpose. Also, move up the declaration of `copy_and_move_impl`.
Signed-off-by: Dennis Liu <[email protected]> With the previous implementation of `copy_and_move_impl`, non-copyable classes would encounter compilation failures due to non-compile-time if-else branching. The compiler would check the deleted copy constructor and assignment in the `else` branch, even though they would never be called. To address this, several helper structs have been implemented to change runtime if-else branching to compile-time if-else branching for C++14. If C++17 is used, we can simply employ `if constexpr` to make the branching compile-time. The test case `e1cc7c9f-c1b5-4047-811b-004302af5c00` (UsingMoveCtorAtNonCopyableTypeShouldCompile) verifies that the implementation works for both C++14 and C++17. The assignment portion will be added in a subsequent commit.
Signed-off-by: Dennis Liu <[email protected]> Based on the discussion at [eclipse-iceoryx#2069 (comment)], additional tests have been incorporated. Furthermore, some statistical results have been updated due to modifications in the `copy_and_move_impl`. For instance, when a non-empty container is moved to an empty container using the move assignment, the `MoveCtor` is the function that is invoked, not the `operator=`. This is because if the slot was previously free, we utilize placement new to ensure proper functionality. Consequently, it is the `MoveCtor` that gets called."
Signed-off-by: Dennis Liu <[email protected]> This commit aims to fix that incorrect member such as `m_begin_free` and `m_begin_used` might cause unexpected erase error (usually terminate at line 515). Hence, the member will be updated after all data are moved or copied into `this` container, ensuring free list and used list return to normal status(not broke by copy or move). Then, `erase` can be called safely. Finally, the correct information from rhs will be assigned to member at the bottom of `copy_and_move_impl`.
Signed-off-by: Dennis Liu <[email protected]> Add a new test case `IteratorsAfterMoveWorkAsExpected`. Remove previous test cases `ContainerIsNotMovable` and `ContainerIsNotCopyable`.
@Dennis40816 I reviewed your PR as well, and it looks like a great job! |
@elfenpiff Thank you so much! I am happy to contribute to the project. |
@Dennis40816 can you create an issue with the sporadically failing test names. When we have time we can look into it, except when you are eager to dig deeper. 😀 |
I saw only two failures during one CI run. It was the bazel and thread sanitizer and looked like the test file was too large but after triggering the CI again it passed. Did you see more of these? If yes, maybe the file with the tests needs to be split into two. |
You're right. But something weird happened. In build-test-ubuntu-with-thread-sanitizer-clang-latest, all constructors were supposed to be invoked, as the destination container was empty, indicating that constructors should be called initially.
And something similar in build-test-ubuntu-bazel |
I found the issue with the flaky tests. The problem is that the values of the m_status
array are not yet initialized in the copy and move ctors. There are basically two options, either manually initialize them with FREE
or copy_and_move_impl
needs to be made aware about being used from a ctor.
Since this PR is already quite large and I like what you did with the I haven't fully thought it through but having something like this enum class SpecialMemberOperation {
CopyConstructor,
CopyAssignment,
MoveConstructor,
MoveAssignment,
}; Could be used as template parameter for the What do you think? |
Oh, and I'm a bit disappointed that the undefined behavior sanitizer did not find the issue with the uninitialized access. I was hoping that it could find issues like this. |
Sounds Interesting! I'll try to create a PR(should the issue be created first or not?) about refactoring |
Do you mean add // transfer src data to destination
for (; rhs_it.to_index() != Index::INVALID; ++i, ++rhs_it)
{
// vvvvvvv
if (is_move && m_status[i] == SlotStatus::USED)
{
#if __cplusplus >= 201703L
if constexpr (is_move)
// ......
for (; i < CAPACITY; ++i)
{
// vvvvvvvv
if (is_move && m_status[i] == SlotStatus::USED)
{
m_data[i].~T();
}
}
// ... Also, I think |
It's up to you. You can either as additional PR of #2052 and if you are successful create another issue to move the helper classes to the |
I'm a bit lost 😅 The more I think about it, the more I come to the conclusion that the code of the default ctor needs to be moved to something like |
Oh my god. You're right. I don't even understand what I was thinking just now. I think I might need to make these modifications tomorrow. I'm sorry for not thinking it through. I think I will follow your suggestion and use an |
No problem :) |
Signed-off-by: Dennis Liu <[email protected]> When we constrcut `FixedPositionContainer`. We need to make sure that internal status `m_status` be initialized correctly. Note that when the constructor (default / copy / move) is called, the lhs member(`m_status`, `m_next`) are all undefined. Therefore, `reset_member` should be used in every ctor.
Signed-off-by: Dennis Liu <[email protected]> It's can be simply replaced by a `for` loop to set m_status to FREE in copyCtor and assignmentCtor. Therefore, no need to add a new function.
iceoryx_dust/container/include/iox/fixed_position_container.hpp
Outdated
Show resolved
Hide resolved
@Dennis40816 congratulations to your first merged PR in iceoryx. Thanks for the patience with me and I'm looking forward to more contributions from you :) |
Pre-Review Checklist for the PR Author
iox-123-this-is-a-branch
)iox-#123 commit text
)task-list-completed
)iceoryx_hoofs
are added to./clang-tidy-diff-scans.txt
Notes for Reviewer
FixedPositionContainer
are implemented.FixedPositionContainer
, only the move/copy assignment of elements withinFixedPositionContainer::m_data
gets triggered (without calling the constructor). This isbecause the
FixedPositionContainer
constructor is realized using assignment, mirroring the behavior ofvector
.build/dust/test/dust_moduletests
:FixedPositionContainer::clear()
has been executed is based on detecting if the element (ComplexType
) has invoked theDTor
.Checklist for the PR Reviewer
iceoryx_hoofs
have been added to./clang-tidy-diff-scans.txt
Post-review Checklist for the PR Author
References