This is an archive of the discontinued LLVM Phabricator instance.

[libc++] Add the std::ranges::drop range adaptor object
AbandonedPublic

Authored by ldionne on Jan 10 2022, 8:53 AM.

Details

Reviewers
Quuxplusone
Group Reviewers
Restricted Project
Summary

This introduces forward declarations of string_view and span to
keep drop_view.h as miminal as possible, and to avoid the possibility
of circular dependencies since span and string_view both depend on
some parts of ranges too. They don't technically depend on drop_view
right now, but this is guarding against future headache.

Diff Detail

Event Timeline

ldionne created this revision.Jan 10 2022, 8:53 AM
ldionne requested review of this revision.Jan 10 2022, 8:53 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 10 2022, 8:53 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript
ldionne updated this revision to Diff 398669.Jan 10 2022, 9:15 AM

Generate missing files.

Quuxplusone requested changes to this revision.Jan 10 2022, 9:38 AM
Quuxplusone added a subscriber: Quuxplusone.

I haven't really looked at the implementation yet, other than to say "ergh, this doesn't look like how I did it." ;) I'll wait for test/forward-declaration updates before looking again, in case the test updates flush out any issues with the implementation.

libcxx/include/CMakeLists.txt
204–205

This introduces forward declarations of string_view and span

On the cost side, there are several red flags associated with this part of the PR:

  • requires unusual-looking modulemap changes
  • introduces a new detail subdirectory (countermeasure: you could simply change the names to __string/stringfwd.h and __span/spanfwd.h, after moving the existing __string file out of the way; I expect that'd look fine)
  • the idea of "forward declarations" in general (counterpoint: they already exist, you're just moving them a bit further away from their corresponding definitions). If we're talking about "future headaches," I would imagine "forward declaration, separated from its definition, accidentally bit-rots and drifts away from that definition" is a vastly more likely headache than anything involving circular dependencies between span and drop_view-etc.

How about renaming these to __string/stringfwd.h and __span/spanfwd.h, and perhaps granularizing the rest of <string> and/or <span> in a preliminary PR while you're at it? (I suggest foofwd.h by analogy with iosfwd. I can see a case for just __foo/fwd.h, but that might be ambiguous when <foo> contains multiple types and only some of them are being forward-declared in the detail header.)

libcxx/test/std/ranges/range.adaptors/range.drop/adaptor.pass.cpp
52

Here and throughout, can you think of a good way to test that result.end() also has its correct value?

88

Simpler: assert(result.empty()), since iota_view provides an .empty() method?

109–115

I'd like to see more value-category tests, i.e. std::views::drop(static_cast<const View&&>(view), 2) for all four interesting cvref-qualifications, and ditto for all four cvref-qualifications on at least one of the "passthrough" types.

This revision now requires changes to proceed.Jan 10 2022, 9:38 AM

Note: it looks like drop is not mentioned in docs/Status/RangesPaper.csv.

Note: it looks like drop is not mentioned in docs/Status/RangesPaper.csv.

Hmm, it looks like that page only tracks things that were in the original One Ranges Proposal, and drop_view was added by P1035 "Input Range Adaptors" (among other things).

ldionne updated this revision to Diff 413925.Mar 8 2022, 1:22 PM

Rebasing onto main -- after talking with @var-const, he'll commandeer this because I'm busy with other stuff at the moment, and we should really get this landed.

Herald added a project: Restricted Project. · View Herald TranscriptMar 8 2022, 1:22 PM
Quuxplusone requested changes to this revision.Mar 9 2022, 5:18 PM
Quuxplusone added inline comments.
libcxx/include/__ranges/drop_view.h
142–143

https://eel.is/c++draft/range.drop#overview-2.2.1
IIUC, this should also permit fixed spans like std::span<T, 42>. This needs a regression test.

151–152

This smells like it doesn't exactly match what's supposed to happen in
https://eel.is/c++draft/range.drop#overview-2.2.4
Note that subranges with StoreSize=true are handled in https://eel.is/c++draft/range.drop#overview-2.3 instead. It's a whole maze.

@var-const, you should definitely take a look at my D115122 for comparison. On glancing at it right now, I'm not sure that I do the subrange bullet points correctly, either, though!

This revision now requires changes to proceed.Mar 9 2022, 5:18 PM
ldionne abandoned this revision.May 9 2022, 7:59 AM

Superseded by D125156