Adjusted how dtors get called on types that don't support non-destructive moves #1874
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The explanation of how the code currently works and why it's a problem:
To fix this, I've adjusted how dtors get called for types that don't support destruction so that the following is upheld:
move_dtorif they are being destructed in aflecs_table_deletecall.flecs_table_deletecallflecs_table_moveif the type does not support non-destructive moves.The reason this dtor needs to happen in
flecs_table_moveis because, while it may be safe to dtor the memory location of a moved object in C++ or C, the same can't be said for Rust. In Rust, a move is essentially a memcpy, except you aren't allowed to dtor or touch the previous values. Therefore, when theflecs_table_deleteruns to fill in the space of the moved components, we can't know which components have been moved and which ones need to be dtor'd, so the only safe option is to assume that it is unconstructed memory, and to handle the dtor during the actual move of the entity between tables, unless the entity is being destroyed. In this case, the memory location should always be valid and should therefore be dtor'd.