This is an archive of the discontinued LLVM Phabricator instance.

[libc++] Use std::ranges::swap_ranges in swap CPO
AbandonedPublic

Authored by jloser on Feb 10 2022, 7:57 AM.

Details

Reviewers
ldionne
Quuxplusone
Mordante
philnik
var-const
Group Reviewers
Restricted Project
Summary

As the comment notes, now that we have implemented std::ranges::swap_ranges,
we can apply it when swapping C-style arrays in the swap CPO when there is
support for ranges.

Diff Detail

Event Timeline

jloser requested review of this revision.Feb 10 2022, 7:57 AM
jloser created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 10 2022, 7:57 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript
ldionne requested changes to this revision.Feb 10 2022, 8:03 AM
ldionne added inline comments.
libcxx/include/__concepts/swappable.h
82–85

I think this is what you want?

This revision now requires changes to proceed.Feb 10 2022, 8:03 AM
philnik added inline comments.Feb 10 2022, 8:03 AM
libcxx/include/__concepts/swappable.h
82–85
jloser updated this revision to Diff 407549.Feb 10 2022, 8:33 AM

Actually use std::ranges::swap_ranges instead of std::swap_ranges.

libcxx/include/__concepts/swappable.h
82–85

Oops, yes. Fixed - thanks!

LGTM if CI is happy. I skimmed the existing tests for ranges::swap and it looks like arrays are covered decently well; but have you also looked at the tests? Do we need any more coverage for this?

LGTM if CI is happy. I skimmed the existing tests for ranges::swap and it looks like arrays are covered decently well; but have you also looked at the tests? Do we need any more coverage for this?

Looks like CI isn't happy as this introduces a header cycle as shown by https://buildkite.com/llvm-project/libcxx-ci/builds/8635#9ef9a18c-716c-4962-9f54-27108fa79d51. We'll need to fix that.

As for the tests, I briefly looked at the array tests and they seemed OK - nothing immediately came to mind that I'd like to add (at least as a result of us using ranges::swap_ranges for swappable arrays).

ldionne requested changes to this revision.Feb 14 2022, 12:59 PM

This LGTM, however I would like to see this again after rebasing on top of D118736. D118736 is a must-have, and I think both are going to be in conflict, so we might have to postpone doing this. Or we could do something like:

#if defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
  // use for loop
#else
  // use ranges::swap_ranges
#endif

Once we stop using _LIBCPP_HAS_NO_INCOMPLETE_RANGES, we can refactor this into only the #else branch.

This revision now requires changes to proceed.Feb 14 2022, 12:59 PM

This LGTM, however I would like to see this again after rebasing on top of D118736. D118736 is a must-have, and I think both are going to be in conflict, so we might have to postpone doing this. Or we could do something like:

#if defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
  // use for loop
#else
  // use ranges::swap_ranges
#endif

Once we stop using _LIBCPP_HAS_NO_INCOMPLETE_RANGES, we can refactor this into only the #else branch.

The #ifdef dance you proposed seems reasonable, and then can clean it up once we stop using _LIBCPP_HAS_NO_INCOMPLETE_RANGES. I haven't had a chance yet to look into fixing the header cycle issue this exposes when including #include <__algorithm/ranges_swap_ranges.h> from <__concepts/swappable.h>. I'll rebase and fix the cycle sometime this week.

jloser updated this revision to Diff 431121.May 20 2022, 9:21 PM
jloser edited the summary of this revision. (Show Details)

Rebase and add #ifdef.

There isn't a "straightforward" way to fix the header cycle since __concepts/movable.h depends on __concepts/swappable.h

Herald added a project: Restricted Project. · View Herald TranscriptMay 20 2022, 9:21 PM
jloser abandoned this revision.May 21 2022, 8:32 AM