This is an archive of the discontinued LLVM Phabricator instance.

[libcxx][NFC] removes `swap`'s dependency on `swap_ranges`
ClosedPublic

Authored by cjdb on Jun 22 2021, 6:56 PM.

Details

Summary

Under the as-if rule, we can directly implement the array overload for
std::swap. By removing this circular dependency where swap is
implemented in terms of swap_ranges and swap_ranges is defined in
terms of swap, we can split them into their own headers. This will:

(a) limit the surface area in which Hyrum's law can bite us;
(b) force users to include the correct headers;
(c) make finding the definitions trivial (swap is a utility,

`swap_ranges` is an algorithm).

Diff Detail

Event Timeline

cjdb requested review of this revision.Jun 22 2021, 6:56 PM
cjdb created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptJun 22 2021, 6:56 PM
Herald added a reviewer: Restricted Project. · View Herald Transcript
Quuxplusone added a subscriber: Quuxplusone.

I initially expected the call to swap, from within a template named swap, to be problematic... but https://godbolt.org/z/hxYaob3eT demonstrates that name lookup seems to be doing the right thing. So, this LGTM, mod two nits!

libcxx/include/type_traits
4192–4193

If what you're doing below works (I think it does), then you should remove lines 4192-4196 because the forward declaration of swap_ranges is no longer needed.

libcxx/test/std/utilities/utility/utility.swap/swap_array.pass.cpp
18 ↗(On Diff #353840)

Style in libcxx/test/ is generally to put the header-under-test first in the list of includes, even though that is out of alphabetical order. Please leave this file untouched. (Leaving the tests untouched is also a good way to prove that your change is really "NFC".)

cjdb updated this revision to Diff 353848.Jun 22 2021, 9:59 PM
  • removes forward declaration of swap_ranges
  • fixes header mishap
mizvekov added inline comments.
libcxx/include/type_traits
4191

Minor minor nit: might as well remove this comment here.

ldionne accepted this revision.Jun 24 2021, 8:25 AM
This revision is now accepted and ready to land.Jun 24 2021, 8:25 AM
This revision was automatically updated to reflect the committed changes.