Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Should mojom-forward.h files be more widely publicised?

83 views
Skip to first unread message

Joe Mason

unread,
Oct 18, 2024, 12:03:44 PM10/18/24
to cxx
Chrome's style guide recommends forward declarations over includes (https://chromium.googlesource.com/chromium/src/+/main/styleguide/c++/c++.md#forward-declarations-vs_includes), and there are some forward-only headers like "callback_forward.h" to facilitate this.

IIUC the generated mojo code for foo.mojom creates "foo.mojom-forward.h", which has only forwards, and "foo.mojom.h" which has the full definitions. So by the spirit of the style guide, header files should #include mojom-forward.h files where possible. But I can't find this explicitly documented anywhere.


Come to think of it, is it worth explicitly mentioning forwarding headers like "callback_forward.h"?

Joe

Peter Kasting

unread,
Oct 18, 2024, 2:44:07 PM10/18/24
to Joe Mason, cxx
I think you're right that forwarding headers are preferred when they suffice. I am ambivalent towards explicitly mentioning that (I don't think it will change behavior much).

I would love to see a limited form of misc-include-cleaner or IWYU suggest these automatically where applicable. 

PK

--
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CAH%3DT95SNPLpJPnE%2Bk0i7gPinAn6a5KG95EX%3D3phdtgJW826P%2BQ%40mail.gmail.com.

danakj

unread,
Oct 22, 2024, 2:52:50 PM10/22/24
to Joe Mason, cxx
On Fri, Oct 18, 2024 at 12:03 PM 'Joe Mason' via cxx <c...@chromium.org> wrote:
Chrome's style guide recommends forward declarations over includes (https://chromium.googlesource.com/chromium/src/+/main/styleguide/c++/c++.md#forward-declarations-vs_includes), and there are some forward-only headers like "callback_forward.h" to facilitate this.

IIUC the generated mojo code for foo.mojom creates "foo.mojom-forward.h", which has only forwards, and "foo.mojom.h" which has the full definitions. So by the spirit of the style guide, header files should #include mojom-forward.h files where possible. But I can't find this explicitly documented anywhere.


Good idea :)

Come to think of it, is it worth explicitly mentioning forwarding headers like "callback_forward.h"?

Maybe as this one is particularly widespread, but don't want to maintain a list of such headers in the style guide either. Maybe a big "USE THE FORWARDING HEADER IN HEADERS" at the top of callback.h would do more?

Joe Mason

unread,
Oct 22, 2024, 6:38:27 PM10/22/24
to danakj, cxx
On Fri, Oct 18, 2024 at 2:44 PM Peter Kasting <pkas...@chromium.org> wrote:
I think you're right that forwarding headers are preferred when they suffice. I am ambivalent towards explicitly mentioning that (I don't think it will change behavior much).

I would love to see a limited form of misc-include-cleaner or IWYU suggest these automatically where applicable. 

Yeah, an automated warning would be better, but I still think it's worthwhile to mention in the docs so reviewers have something to point to.

On Tue, Oct 22, 2024 at 2:52 PM danakj <dan...@chromium.org> wrote:
Come to think of it, is it worth explicitly mentioning forwarding headers like "callback_forward.h"?

Maybe as this one is particularly widespread, but don't want to maintain a list of such headers in the style guide either. Maybe a big "USE THE FORWARDING HEADER IN HEADERS" at the top of callback.h would do more?

I just meant mentioning the concept of forwarding headers, not a complete list. I put up https://crrev.com/c/5953868 for review, which uses callback_forward.h as "an example" of a forwarding header, and also mentions the mojo-generated ones since they're harder to find in a code search. WDYT?

Also, callback.h already has a blurb like that. Maybe it could be bigger, though.


Claudio DeSouza

unread,
Nov 11, 2024, 7:23:20 PM11/11/24
to cxx, cxx
I was doing a few test today with IWYU, and actually these headers get automatically selected with a tool like that. Something to bear in mind.

Claudio.

Reply all
Reply to author
Forward
0 new messages