Closed Bug 1922586 Opened 2 years ago Closed 1 year ago

Stylo bindgen handles UniquePtr poorly

Categories

(Firefox Build System :: Toolchains, enhancement)

enhancement

Tracking

(firefox142 fixed)

RESOLVED FIXED
142 Branch
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.

Flags: needinfo?(emilio)
See Also: → 1454816
Assignee: nobody → emilio
Flags: needinfo?(emilio)

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.

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: