Repository navigation
[NFC] Remove IsRelocatable's TODO; it's more of a WONTDO - #2116
Closed
Quuxplusone wants to merge 1 commit into
Closed
Quuxplusone wants to merge 1 commit into
Quuxplusone wants to merge 1 commit into
Conversation
See 93b0f54 (introducing the TODO comment, 2012-12-05); bb19b30 (implementing it in code, 2019-02-27, GitHub PR meta#1035); 3f7a734 (reverting it back to a comment, 2019-02-28). My understanding is that the revert was for toolchain reasons, not semantic reasons. My argument below is for semantic reasons. As I understand the comment, it's saying that we can productively assume that any type that's trivially move-constructible is also trivially relocatable; thus we could change : std::conditional< sizeof(T) && is_detected_v<traits_detail::detect_IsRelocatable, T>, traits_detail::has_true_IsRelocatable<T>, - is_trivially_copyable<T>>::type {}; + std::is_trivially_move_constructible<T>>::type {}; - Pro: I can't think of a _non-contrived_ example of a type which is trivially move-constructible but not trivially relocatable. That is, the proposed change would be mostly harmless. However: - Con: The most common trivially-relocatable types (vector, unique_ptr) are not trivially move-constructible, so this would be a no-op on all types except very contrived ones. - In fact, I would go so far as to say that any type which is trivially move-constructible yet NOT trivially copyable is probably a bug! - Con: An RAII type such as `struct S { S(); ~S(); }` is trivially move-constructible, but not trivially copyable because it's not trivially destructible; and without further annotation, we should NOT assume that `S` is trivially relocatable (because that non-trivial destructor might be significant to the user). - Suppose `S` were (Platonically) trivially relocatable after all. Then adding `S(S&&) = delete` to it shouldn't change the fact that it's trivially relocatable (e.g. in `vector<S>::erase`, which doesn't require move-construction, just move-assignment and destruction). Therefore anything based on `is_*_constructible` seems like the wrong tool for the job; it'll report `false` for some types that we could in fact trivially relocate. (`is_trivially_copyable` and the proposed `is_trivially_relocatable` will still report `true` for types with deleted special members.) Conclusion: The current code is already at a (local) optimum; replacing `is_trivially_copyable` with anything involving `is_trivially_move_constructible` would be a regression. Replacing it with `__is_trivially_relocatable(T)` on compilers that support it (currently just Clang) could be a good idea. For now, simply removing the TODO seems like a step in the right direction.
Quuxplusone
force-pushed
the
remove-todo
branch
from
December 31, 2023 21:05
348cdfd to
0c44103
Compare
Contributor
|
@Orvid has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
Contributor
facebook-github-bot
pushed a commit
to meta/hhvm
that referenced
this pull request
Jan 23, 2024
Summary: (attn JoeLoser, mengz0, yfeldblum) See 93b0f543f2 (introducing the TODO comment, 2012-12-05); bb19b3016d (implementing it in code, 2019-02-27, GitHub PR meta/folly#1035); 3f7a734cee (reverting it back to a comment, 2019-02-28). My understanding is that the revert was for toolchain reasons, not semantic reasons. My argument below is for semantic reasons. As I understand the comment, it's saying that we can productively assume that any type that's trivially move-constructible is also trivially relocatable; thus we could change : std::conditional< sizeof(T) && is_detected_v<traits_detail::detect_IsRelocatable, T>, traits_detail::has_true_IsRelocatable<T>, - is_trivially_copyable<T>>::type {}; + std::is_trivially_move_constructible<T>>::type {}; - Pro: I can't think of a _non-contrived_ example of a type which is trivially move-constructible but not trivially relocatable. That is, the proposed change would be mostly harmless. However: - Con: The most common trivially-relocatable types (vector, unique_ptr) are not trivially move-constructible, so this would be a no-op on all types except very contrived ones. - In fact, I would go so far as to say that any type which is trivially move-constructible yet NOT trivially copyable is probably a bug! - Con: An RAII type such as `struct S { S(); ~S(); }` is trivially move-constructible, but not trivially copyable because it's not trivially destructible; and without further annotation, we should NOT assume that `S` is trivially relocatable (because that non-trivial destructor might be significant to the user). - Suppose `S` were (Platonically) trivially relocatable after all. Then adding `S(S&&) = delete` to it shouldn't change the fact that it's trivially relocatable (e.g. in `vector<S>::erase`, which doesn't require move-construction, just move-assignment and destruction). Therefore anything based on `is_*_constructible` seems like the wrong tool for the job; it'll report `false` for some types that we could in fact trivially relocate. (`is_trivially_copyable` and the proposed `is_trivially_relocatable` will still report `true` for types with deleted special members.) Conclusion: The current code is already at a (local) optimum; replacing `is_trivially_copyable` with anything involving `is_trivially_move_constructible` would be a regression. Replacing it with `__is_trivially_relocatable(T)` on compilers that support it (currently just Clang) could be a good idea. For now, simply removing the TODO seems like a step in the right direction. X-link: meta/folly#2116 Reviewed By: Gownta Differential Revision: D52975801 Pulled By: Orvid fbshipit-source-id: a78ea99659574c56a3987631b90ecb917e5cb672
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
(attn @JoeLoser, @mengz0, @yfeldblum)
See 93b0f54 (introducing the TODO comment, 2012-12-05); bb19b30 (implementing it in code, 2019-02-27, GitHub PR #1035); 3f7a734 (reverting it back to a comment, 2019-02-28). My understanding is that the revert was for toolchain reasons, not semantic reasons. My argument below is for semantic reasons.
As I understand the comment, it's saying that we can productively assume that any type that's trivially move-constructible is also trivially relocatable; thus we could change
However:
Con: The most common trivially-relocatable types (vector, unique_ptr) are not trivially move-constructible, so this would be a no-op on all types except very contrived ones.
In fact, I would go so far as to say that any type which is trivially move-constructible yet NOT trivially copyable is probably a bug!
Con: An RAII type such as
struct S { S(); ~S(); }is trivially move-constructible, but not trivially copyable because it's not trivially destructible; and without further annotation, we should NOT assume thatSis trivially relocatable (because that non-trivial destructor might be significant to the user).Suppose
Swere (Platonically) trivially relocatable after all. Then addingS(S&&) = deleteto it shouldn't change the fact that it's trivially relocatable (e.g. invector<S>::erase, which doesn't require move-construction, just move-assignment and destruction). Therefore anything based onis_*_constructibleseems like the wrong tool for the job; it'll reportfalsefor some types that we could in fact trivially relocate. (is_trivially_copyableand the proposedis_trivially_relocatablewill still reporttruefor types with deleted special members.)Conclusion: The current code is already at a (local) optimum; replacing
is_trivially_copyablewith anything involvingis_trivially_move_constructiblewould be a regression. Replacing it with__is_trivially_relocatable(T)on compilers that support it (currently just Clang) could be a good idea. For now, simply removing the TODO seems like a step in the right direction.