rm IsPod in TypeTraits.h; use std::is_pod/has_trivial_assignment/etc instead
Categories
(Core :: MFBT, defect)
Tracking
()
People
(Reporter: luke, Unassigned)
References
Details
Comment 1•12 years ago
|
||
| Reporter | ||
Comment 2•12 years ago
|
||
| Reporter | ||
Comment 3•12 years ago
|
||
Comment 4•12 years ago
|
||
Comment 5•9 years ago
|
||
| Reporter | ||
Comment 6•9 years ago
|
||
Comment 7•9 years ago
|
||
Comment 8•7 years ago
|
||
Comment 9•7 years ago
|
||
Comment 10•7 years ago
|
||
Comment 11•7 years ago
|
||
Comment 12•7 years ago
|
||
Comment 13•5 years ago
|
||
Is there any update here? Asking specifically about whether or not there is a version of IsPod that we can use here
Comment 14•5 years ago
•
|
||
I would encourage new code to use standard type traits like std::is_trivial and std::is_standard_layout.
Unfortuantely, for the IPC use case in particular, I'm not sure what would be a useful trait:
mozilla::Maybepassesstd::is_standard_layout, thus making it ineffective for the sorts of cases we want to catch- any type with a user-defined constructor or even a default member initializer fails
std::is_trivial(andstd::is_pod), and pretty much all of our IPC structs have one or the other to make sure all their fields are initialized
Comment 15•5 years ago
|
||
std::is_trivially_copyable?
Comment 16•5 years ago
|
||
Note that historically, I've encountered various std::is_trivially_* that were not actually implemented on all the STLs we use. Or at least just one. The one I'm thinking of is currently used/hacked around here:
However, I made no actual effort to future-proof that into something that would alert me when I could ultimately use the trait unconditionally, so it's possible it actually can just be used directly now.
Comment 17•5 years ago
|
||
(In reply to Jeff Walden [:Waldo] from comment #16)
Note that historically, I've encountered various
std::is_trivially_*that were not actually implemented on all the STLs we use. Or at least just one. The one I'm thinking of is currently used/hacked around here:
For IPC purposes it doesn't matter if is_trivially_copyable isn't implemented in all the STLs we use. We just need it to be implemented in at least one platform that gets built in CI, since we'll just be doing a static_assert and if even one build fails as a result it's good enough.
From my reading of is_trivially_copyable it sounds like what we want. Botond, do you think it's appropriate for this purpose? If there's a handful of classes that we're currently using with PlainOldDataSerializer that don't pass is_trivially_copyable it's not big deal as I can try to make them trivially copyable or just explicitly serialize them.
Comment 18•5 years ago
|
||
(In reply to Kartikaya Gupta (email:kats@mozilla.com) from comment #17)
From my reading of
is_trivially_copyableit sounds like what we want. Botond, do you think it's appropriate for this purpose?
Yup, is_trivially_copyable sounds like it should work. Seems to tick our boxes such as rejecting Maybe, and not imposing requirements on how default construction behaves.
Thanks, :emk, for the suggestion!
Comment 19•5 years ago
|
||
I filed https://bugzilla.mozilla.org/show_bug.cgi?id=1622344 for adding the static_assert and using is_trivially_copyable. This bug seems wider in scope so I didn't want to hijack it.
Comment 20•5 years ago
|
||
For example, in nsTArray (https://searchfox.org/mozilla-central/rev/9c6e7500c0015a2c60be7b1b888261d95095ce27/xpcom/ds/nsTArray.h#2392) I think std::is_trivially_copy_constructible_v could/should be used instead. I am just wondering if there are types for which mozilla::IsPod is specialized where the value of std::is_trivially_copy_constructible_v would not match. Do we need to analyze this for all types, or can we just replace the type trait?
Comment 21•5 years ago
|
||
We should probably check the value of std::is_trivially_copy_constructible_v for types for which mozilla::IsPod is specialized. Based on a Searchfox search, there are only a handful of such types (not counting built-in types).
Comment 22•5 years ago
|
||
(In reply to Botond Ballo [:botond] from comment #21)
We should probably check the value of
std::is_trivially_copy_constructible_vfor types for whichmozilla::IsPodis specialized. Based on a Searchfox search, there are only a handful of such types (not counting built-in types).
Right, I somehow assumed there were more uses. That's a number that can be checked. Will do that, and report back here.
Comment 23•5 years ago
|
||
I added corresponding assertions (see https://hg.mozilla.org/try/rev/ca81b66c923853d086973c9e38a81d4df79fec24): After resolving Bug 1626197, all types with IsPod specializations are trivially copyable, except for HashMapEntry, which is not copyable at all, but move-only.
Comment 24•5 years ago
|
||
I have a local patch to remove most IsPod from js/src (except when used for the mozilla::Vector POD-specialization), so I don't think you need to worry much about HashMapEntry. (I think HashMapEntry only uses IsPod for https://searchfox.org/mozilla-central/rev/fa2df28a49883612bd7af4dacd80cdfedcccd2f6/js/src/frontend/NameCollections.h#164-165.)
Updated•3 years ago
|
Description
•