This is an archive of the discontinued LLVM Phabricator instance.

[libcxx] span: Cleanup includes
ClosedPublic

Authored by miscco on Dec 31 2019, 4:50 AM.

Details

Summary

Remove the duplicated include of <cstddef> and forward declare std::array rather than dragging in the header.

Event Timeline

miscco created this revision.Dec 31 2019, 4:50 AM
mclow.lists requested changes to this revision.Jan 1 2020, 7:48 AM

I'm fine with the other changes here, but not the array change.

libcxx/include/span
148

Forward declaring array will lead to other problems down the road.
Visibility problems. Which lead to ODR violations.

This revision now requires changes to proceed.Jan 1 2020, 7:48 AM
mclow.lists added inline comments.Jan 1 2020, 7:49 AM
libcxx/include/span
132

Let's make the comment "for ptrdiff_t and byte"

miscco marked 2 inline comments as done.Jan 1 2020, 8:32 AM

Some comments

libcxx/include/span
132

As far as I can see ptrdiff_t was only needed for the old index_type. So I would ommit it here.

148

I would disagree. It is essentially only used by the deduction guides. So to use it one has to already have array included.

I would say the other way is surprising as shown in the test, where the array header was not included but used.

That said I would not really make a stand Herr.

mclow.lists added inline comments.Jan 2 2020, 1:26 PM
libcxx/include/span
148

if you look in <array>, you will see the following declaration:

template <class _Tp, size_t _Size>
struct _LIBCPP_TEMPLATE_VIS array

Your forward declaration is different.

Also, for some definitions of _LIBCPP_TEMPLATE_VIS, it can only be on the first declaration of the template in any translation unit. How would you enforce this?

bcraig added a subscriber: bcraig.Jan 2 2020, 1:43 PM
bcraig added inline comments.
libcxx/include/span
148

A solution to this would be to have an <array_fwd> header (or perhaps even a general <libcxx_fwd> header) that had all the expensive forward declarations, then ensured that <array> pulled in <__array_fwd>.

Difficulty: This increases the number of headers that clients pull in. I don't personally think that's a big deal, but I seem to recall that the quantity of headers is something that this project tends to be picky about.

miscco updated this revision to Diff 236002.Jan 3 2020, 1:33 AM

Do not forward declare array

miscco marked an inline comment as done.Jan 3 2020, 1:34 AM

Removed the forward declaration of array as that would be far more involved.

ldionne accepted this revision.Feb 11 2020, 2:15 AM

Looks like you implemented the requested changes, and this LGTM. Thanks!

FWIW, I'm favorable to the idea of having forward declaration headers, however I think we have a lot of work to do before this makes sense, like splitting up the header files containing definitions. I think I would like to see this done as a concentrated effort instead of ad-hoc patches.

This revision was not accepted when it landed; it landed in state Needs Review.Feb 11 2020, 2:22 AM
This revision was automatically updated to reflect the committed changes.