This is an archive of the discontinued LLVM Phabricator instance.

[libcxx][nfc] Remove <algorithm>'s dependence on <iterator> and related changes.
AbandonedPublic

Authored by zoecarver on Jul 7 2021, 12:48 PM.

Details

Reviewers
Quuxplusone
ldionne
cjdb
Group Reviewers
Restricted Project
Summary

This removes a few dependencies on <iterator> which removes the dependency cycle between iterator -> variant -> array -> iterator and iterator -> algorithm -> iterator and iterator -> memory -> algorithm -> iterator so that we can use variant in common_iterator.

Diff Detail

Event Timeline

zoecarver created this revision.Jul 7 2021, 12:48 PM
zoecarver requested review of this revision.Jul 7 2021, 12:48 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 7 2021, 12:48 PM
Herald added a reviewer: Restricted Project. · View Herald Transcript
zoecarver updated this revision to Diff 357056.Jul 7 2021, 12:52 PM

Rebase on main.

A simpler way to say the words in the title: this removes <algorithm>'s dependency on both <memory> and <iterator>. (<memory> still depends on <iterator>.)

zoecarver updated this revision to Diff 357059.Jul 7 2021, 1:06 PM

Fix rebase fallout (in <iterator>).

Quuxplusone added inline comments.
libcxx/include/__algorithm/equal.h
17

a-z plz

libcxx/include/__algorithm/is_permutation.h
18

a-z plz (and throughout, anywhere I missed)

libcxx/include/__functional/function.h
24

a-z plz

libcxx/include/algorithm
654–656

This line is duplicated (see below in a-z order)

libcxx/include/array
116 ↗(On Diff #357059)

a-z plz

libcxx/include/functional
518 ↗(On Diff #357059)

As @EricWF and @ldionne (and I) have said, removing user-visible inclusions really ought to be done in separate commits and advertised. If we're breaking

#include <functional>
std::unique_ptr<int> p;

then that needs to be advertised somehow before we do it. Or discussed. Or something. (I mean, we just keep churning these headers — I'm sure we've broken many things already — but expect to keep hearing the same old squeaky wheels until the churn stops.)

cjdb requested changes to this revision.EditedJul 7 2021, 1:22 PM

Splitting stuff out of <memory> is good, but please don't remove any header inclusions just yet. A cross-sectional plan (that I'm working out) needs to be put into place before we can delete our inclusions.

EDIT: if we need to remove something, we'll need to precisely document it in our release notes (including why we needed to push the deletion ahead of schedule), and give users the chance to respond to this change.

This revision now requires changes to proceed.Jul 7 2021, 1:22 PM

EDIT: if we need to remove something, we'll need to precisely document it in our release notes (including why we needed to push the deletion ahead of schedule), and give users the chance to respond to this change.

If we want to use variant in common_iterator (which I am neutral on at best) we do need to remove something. We can do one of the following:

  1. Remove <iterator> and <algorithm> from <array>
  2. Remove <memory> and <iterator> from <algorithm> (current).

Putting this here preemptively: based on recent discussions, I'm going to do the first one, as that seems to be lower-impact. I'm also going to keep all the changes to internal headers, but make sure that external headers still provide the same includes (except for <array>).

ldionne accepted this revision.Jul 7 2021, 2:24 PM

Zoe and I just spoke.

He's going to turn this into a NFC where we don't remove includes from the "public" headers, but still split stuff out of <memory>.

In a follow-up patch, we can try to break the cycle between <variant> and <array> by using a raw C array in variant's implementation and removing #include <array> from <variant>. Yes, that will be a breaking change. But I don't think we need a formal release note and discussion for just that one - we've been making small breaking changes such as this without even noticing it for years. While we should have a discussion if we're going to do something major and systematic like in D104980, we shouldn't prevent ourselves from making progress for something as simple as this.

This LGTM once the patch is updated to be a NFC (giving thumbs up proactively because we're not in the same time zone and I want this to be unblocked).

zoecarver updated this revision to Diff 357085.Jul 7 2021, 2:58 PM
  • Alphabatize.
  • Update module map.
  • Make this a NFC for real.
cjdb accepted this revision.Jul 8 2021, 9:30 AM

Now that it's NFC, also proactively LGTMing.

This revision is now accepted and ready to land.Jul 8 2021, 9:30 AM
zoecarver updated this revision to Diff 357263.Jul 8 2021, 10:00 AM

Fix modules build (fully expecting it to crash).

zoecarver abandoned this revision.Jul 8 2021, 10:57 AM

I may pick this patch up again later, but for now, I am not going to spend hours debugging why clang is crashing. This patch is not blocking anything.