This is an archive of the discontinued LLVM Phabricator instance.

[libcxx][docs] Add section for header layout and guidlines.
Needs RevisionPublic

Authored by zoecarver on Apr 22 2021, 12:00 PM.

Details

Reviewers
Quuxplusone
ldionne
Mordante
cjdb
Group Reviewers
Restricted Project

Diff Detail

Event Timeline

zoecarver requested review of this revision.Apr 22 2021, 12:00 PM
zoecarver created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptApr 22 2021, 12:00 PM
Herald added a reviewer: Restricted Project. · View Herald Transcript
cjdb accepted this revision.Apr 22 2021, 12:04 PM

LGTM, possibly add another bullet point saying that tiny elements don't get their own header (e.g. the contents of <type_traits> won't be split into loads of tiny headers with exactly one query or modifier and its shorthand).

libcxx/docs/Contributing.rst
72–74

I think a bit more justification on why this is undesirable is necessary.

Thanks for documenting this! In general I like it a lot, but I've some suggestions for improvments.

libcxx/docs/Contributing.rst
71

Please add a bullet these headers should have a .h extension.

72–74

+1 it would be nice it this bullet gives a bit more guidance.

78

Maybe add the reason why it's required? For example Thid inclusion is mandatory since the standard requires the header to provide these declarations.

78

Can you add a bullet that the synopsis should be in the parent header and not duplicated in the sub-header?

libcxx/docs/Contributing.rst
70–71

Stronger: The current naming convention is exactly __<toplevelheadername>/<featurename>.h. toplevelheadername must be the exact name of whatever header the Standard requires to contain this feature, e.g. string or ranges or memory. featurename should be the exact public identifier of the feature defined in this header, e.g. iterator_traits or construct_at. Exceptions exist (e.g. maybe __iterator/iterator_tags.h; __functional/ops.h) but I expect those exceptions are very rare.

If we enforce the general rule "Name the header after what it defines," then we successfully prevent most attempts to introduce "__detail/utils.h" (because detail is not the name of a top-level header and utils is not a public identifier).

75–78

Someone likes the word "imperative" lately. :)
I suggest: All libc++ headers, both public and helper headers, should "Include What You Use." You should never rely on some other header to transitively include something that you need. If your header needs a definition of iterator_traits, then you should either #include <iterator> (exactly as user code does), or, to improve compile speed, #include <__iterator/iterator_traits.h>. You should never expect iterator_traits to be "pulled in" by any other header.
User code, on the other hand, should never #include any of these helper headers directly; they are intended as unstable implementation details of libc++.

zoecarver updated this revision to Diff 339771.Apr 22 2021, 1:33 PM
  • Apply feedback
libcxx/docs/Contributing.rst
75–78

Someone likes the word "imperative" lately. :)

:) sometimes I like a word and it gets stuck in my mind so I use it frequently.

ldionne requested changes to this revision.Apr 23 2021, 9:33 AM
ldionne added inline comments.
libcxx/docs/Contributing.rst
75

I don't see a reason to mandate that. I also don't see a reason to go more than one level deep, but I would just not mention that in the policy since it otherwise creates a rule without having a real reason to. I think we can create the rule later if we do have a concrete reason to prohibit multiple levels.

78

I disagree with this rule as it mandates a too high granularity for headers. I think it's entirely reasonable to bundle several public names into the same header if they are related.

An example of that is __memory/shared_ptr.h. It would be crazy to define std::make_shared in a separate header even though it's technically a different public name. The rule should be to try and group things that are logically related together in a way that makes sense, but I don't think we can have a 100% systematic rule here. We'll always have to use our judgement, and that's fine.

80–88

Include-what-you-use is different from requiring that all sub-headers are included by their parent header. I think they should be separate points.

This revision now requires changes to proceed.Apr 23 2021, 9:33 AM
libcxx/docs/Contributing.rst
75

I think we can create the rule later if we do have a concrete reason to prohibit multiple levels.

The most likely concrete reason would be, "Someone tried to actually do it." I'd much rather have the rule, and make the prospective-rule-breaker ask to open a discussion about changing the rule; than not have the rule, and permit the prospective-rule-breaker to submit a full-fledged PR for something and then defend it like "well, there's no rule against what I'm doing here." The whole point of D101098 as I understand it is to give us a place to point to and say, yes, there is a rule against that, because people cannot be [trusted and/or assumed] to figure this stuff out by osmosis anymore.

78

FWIW, I agree about shared_ptr+make_shared. I would still like something in writing discouraging the use of "utils" or "helpers" headers.
Perhaps it's useful to say: A header, even an internal one, should be able to state clearly either "what concrete feature it exports" or "its reason for being a separate header." Headers that do not exist for a clearly defined performance reason and do not export a clearly delineated concrete library feature (such as "shared_ptr and friends" or "iterator_traits and its supporting details") probably should not exist.

I like the shape this patch takes. Before approving I like to see all review comments addressed.

libcxx/docs/Contributing.rst
69

s/whatever/the/, sounds better IMO.

ldionne added inline comments.Apr 30 2021, 2:08 PM
libcxx/docs/Contributing.rst
75

Let's word it as "We try to keep directories no more than one level deep to keep things simple." That way it's not worded as a hard rule but we still mention it, so you've got your "place to point at" if you want to push back on a review that has abusive usage of nested directories.

78

I agree with that. We want to discourage utility headers that are just a mash-up of "useful things", and this doc should mention it.

cjdb resigned from this revision.Jan 18 2022, 1:38 PM