Page MenuHomePhabricator

[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

Unit TestsFailed

TimeTest
110 mslibcxx CI C++03 > llvm-libc++-shared-cfg-in.libcxx/lint::lint_headers.sh.py
Script: -- : 'RUN: at line 1'; /usr/bin/python3.8 /home/libcxx-builder/.buildkite-agent/builds/7ec79a69e21e-1/llvm-project/libcxx-ci/libcxx/test/libcxx/lint/lint_headers.sh.py
50 mslibcxx CI C++03 > llvm-libc++-shared-cfg-in.libcxx/lint::lint_modulemap.sh.py
Script: -- : 'RUN: at line 1'; /usr/bin/python3.8 /home/libcxx-builder/.buildkite-agent/builds/7ec79a69e21e-1/llvm-project/libcxx-ci/libcxx/test/libcxx/lint/lint_modulemap.sh.py
150 mslibcxx CI C++11 > llvm-libc++-shared-cfg-in.libcxx/lint::lint_headers.sh.py
Script: -- : 'RUN: at line 1'; /usr/bin/python3.8 /home/libcxx-builder/.buildkite-agent/builds/b706d76ce8e9-1/llvm-project/libcxx-ci/libcxx/test/libcxx/lint/lint_headers.sh.py
70 mslibcxx CI C++11 > llvm-libc++-shared-cfg-in.libcxx/lint::lint_modulemap.sh.py
Script: -- : 'RUN: at line 1'; /usr/bin/python3.8 /home/libcxx-builder/.buildkite-agent/builds/b706d76ce8e9-1/llvm-project/libcxx-ci/libcxx/test/libcxx/lint/lint_modulemap.sh.py
10,010 mslibcxx CI C++2b > llvm-libc++-shared-cfg-in.libcxx::clang_tidy.sh.cpp
Script: -- : 'RUN: at line 11'; clang-tidy /home/libcxx-builder/.buildkite-agent/builds/dc323b72550c-1/llvm-project/libcxx-ci/libcxx/test/libcxx/clang_tidy.sh.cpp --warnings-as-errors=* -header-filter=.* -- -Wno-unknown-warning-option -nostdinc++ -I /home/libcxx-builder/.buildkite-agent/builds/dc323b72550c-1/llvm-project/libcxx-ci/build/generic-cxx2b/include/c++/v1 -I /home/libcxx-builder/.buildkite-agent/builds/dc323b72550c-1/llvm-project/libcxx-ci/build/generic-cxx2b/include/c++/v1 -I /home/libcxx-builder/.buildkite-agent/builds/dc323b72550c-1/llvm-project/libcxx-ci/libcxx/test/support -std=c++2b -Werror -Wall -Wextra -Wshadow -Wundef -Wno-unused-command-line-argument -Wno-attributes -Wno-pessimizing-move -Wno-c++11-extensions -Wno-user-defined-literals -Wno-noexcept-type -Wno-atomic-alignment -Wsign-compare -Wunused-variable -Wunused-parameter -Wunreachable-code -Wno-unused-local-typedef -D_LIBCPP_DISABLE_AVAILABILITY -fcoroutines-ts -Werror=thread-safety -Wuser-defined-warnings -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
View Full Test Results (464 Failed)

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
226–227

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
53

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

89

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

110–116

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.Mon, May 9, 7:59 AM

Superseded by D125156