Stylo bindgen handles UniquePtr poorly
Categories
(Firefox Build System :: Toolchains, enhancement)
Tracking
(firefox142 fixed)
| Tracking | Status | |
|---|---|---|
| firefox142 | --- | fixed |
People
(Reporter: nika, Assigned: emilio)
References
Details
Attachments
(2 external files)
Stylo configures rust-bindgen to replace the UniquePtr type with UniquePtr_Simple (https://searchfox.org/mozilla-central/rev/f0b3dafb55f1e7904847f5dc889f131040789ba6/layout/style/nsStyleStruct.h#2144-2156) in order to allow it to be properly handled by rust-bindgen. This is (in part) because the default translation handles UniquePtr poorly due to the heavy use of template specialization and other tricks to make the Deleter member take up no space when it is an empty type (https://searchfox.org/mozilla-central/rev/f0b3dafb55f1e7904847f5dc889f131040789ba6/mfbt/UniquePtr.h#197).
This in particular causes problems due to the UniquePtrExtensions.h header being somewhat widely included, and declaring the UniqueFileHandle, UniqueMachSendRight and UniqueMachReceiveRight type aliases, which are all specializations of UniquePtr with custom deleters which replace the pointer member with a non-pointer-sized handle.
Other types, such as UniqueContentParentKeepAlive also exist which have non-empty deleters which will also not work properly if ever included from a stylo header.
Currently the types in UniquePtrExtensions are disabled when the RUST_BINDGEN macro is defined to avoid this issue, however this may become infectious (as has been the case in https://phabricator.services.mozilla.com/D224152#inline-1246013), as the type not being present could lead to cascading build failures when building rust bindings.
It'd be nice if bindgen could handle this case more gracefully somehow.
| Reporter | ||
Updated•2 years ago
|
| Assignee | ||
Updated•1 year ago
|
| Assignee | ||
Comment 1•1 year ago
|
||
std::unique_ptr's subtleties are hard for bindgen to cope with.
Bug 1973598 was going to make this workaround even uglier by having to figure
out the specific path for std::unique_ptr in the standard library.
Rather than assuming that all usage bindgen sees is simple, explicitly opt in
the few pointers that we need via a new BindgenUniquePtr, and make opaque the
rest.
| Assignee | ||
Comment 2•1 year ago
|
||
Comment 7•1 year ago
|
||
| bugherder | ||
https://hg.mozilla.org/mozilla-central/rev/fe56052ef563
https://hg.mozilla.org/mozilla-central/rev/ffa735da5e99
https://hg.mozilla.org/mozilla-central/rev/a101208b58a9
https://hg.mozilla.org/mozilla-central/rev/fc81596f2ea7
Description
•