This is an archive of the discontinued LLVM Phabricator instance.

[libc++][spaceship] Implement `operator<=>` for `list`
ClosedPublic

Authored by avogelsgesang on Aug 20 2022, 1:54 PM.

Details

Summary

Implements part of P1614R2 "The Mothership has Landed"

Diff Detail

Event Timeline

avogelsgesang created this revision.Aug 20 2022, 1:54 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 20 2022, 1:54 PM
Herald added a subscriber: yaxunl. · View Herald Transcript
avogelsgesang requested review of this revision.Aug 20 2022, 1:54 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 20 2022, 1:54 PM
Herald added a reviewer: Restricted Project. · View Herald Transcript

update review link

One thing I have thought about in our march towards finishing the lexically ordered containers is that we should be able to write a test utils header with one or more templated test functions that will work for most or all of these containers. We can possibly even add (in another header?) some helpful types like weakly ordered ints, types that compare with user orderings, etc. so we don't have to keep writing them over and over. This feels fairly sane to me but I don't know what the general vibe is on how DRY is too DRY for our test suite, and maybe it's better to just copy-paste those parts of the code each time.

libcxx/test/std/containers/sequences/list/compare.pass.cpp
47 ↗(On Diff #454251)

I recommend simply adding another file, such as compare.three_way.pass.cpp, that marks standard versions before 20 as unsupported, then simply does the test. Adding the parts of the test you want to conditionally execute with dozens of conditional directives is honestly too much noise with no real benefit.

Don't forget the SFINAE tests! They should be pretty easy to do here as well. We should be able to test ordering behavior and SFINAE for all of the following:

  1. strongly ordered types
  2. partially ordered types
  3. weakly ordered types
  4. synth-ordered types (weak_ordering)
  5. custom user-ordering types (also causes synthesized weak_ordering)
  6. unordered types (SFINAE should cause the operator to not participate)

All of these should be trivially reusable or easily copyable to the other container types.

jloser added a subscriber: jloser.Aug 21 2022, 6:52 AM

One thing I have thought about in our march towards finishing the lexically ordered containers is that we should be able to write a test utils header with one or more templated test functions that will work for most or all of these containers. We can possibly even add (in another header?) some helpful types like weakly ordered ints, types that compare with user orderings, etc. so we don't have to keep writing them over and over. This feels fairly sane to me but I don't know what the general vibe is on how DRY is too DRY for our test suite, and maybe it's better to just copy-paste those parts of the code each time.

I'm very +1 for that direction of having a reusable header with common types and functions for this.

I think I also agree on the comments with regard to the tests

libcxx/include/list
2341

_LIBCPP_HIDE_FROM_ABI

2341

perhaps I missed something but have you included the header that defines __synth_three_way_result

avogelsgesang added inline comments.Aug 21 2022, 1:30 PM
libcxx/include/list
2341

the complete <compare> header is a standard-mandated include. See line 226

Mordante added inline comments.Aug 31 2022, 1:07 PM
libcxx/test/std/containers/sequences/list/compare.pass.cpp
47 ↗(On Diff #454251)

I like the general idea! How about instead add a generic header file and make it possible to use the functions in there for the tests? Like we do in the test_comparisons.h header. That way the tests are at the expected location.

WDYT?

avogelsgesang marked 2 inline comments as done.

Introduce reusable test function

libcxx/test/std/containers/sequences/list/compare.pass.cpp
47 ↗(On Diff #454251)

Good idea. I introduced test_container_comparisons.h to contain those test helpers. In the future, we should also add a similar utility to test containers like std::map, std::set.

The test functions are already written with std::vector in mind, i.e. they are constexpr and return true, so they can be used to test the constexpr-ness of std::vector.

custom user-ordering types (also causes synthesized weak_ordering)

How do I write such a user-ordering?

Mordante added inline comments.Feb 18 2023, 5:41 AM
libcxx/test/std/containers/sequences/list/compare.three_way.pass.cpp
21
libcxx/test/support/test_container_comparisons.h
10

Please add include guards.

14
61
78

I think these tests can be extended a bit, it feels like they now use a small number of types. I also miss tests for <= to be true/false for certain values.

avogelsgesang marked 3 inline comments as done.

Address review comments

libcxx/test/support/test_container_comparisons.h
78

I am not sure I understand what you are asking for here

use a small number of types

which additional types would you like to see? Afaict, the test case covers enough types such that we have all comparison categories covered?

I also miss tests for <= to be true/false for certain values.

testOrder calls testComparisonsComplete which also covers <=. Or am I misunderstanding your request for additional test coverage

avogelsgesang marked an inline comment as done.Feb 19 2023, 3:54 PM
Mordante accepted this revision.Feb 26 2023, 4:38 AM

LGTM after the CI is green.

libcxx/test/support/test_container_comparisons.h
78

I missed the types where <=> is synthesized, but it's there too.

This revision is now accepted and ready to land.Feb 26 2023, 4:38 AM
ldionne accepted this revision.Feb 27 2023, 10:06 AM
ldionne added a subscriber: ldionne.

LGTM w/ green CI. Thanks!

libcxx/include/list
2345

This should fix your CI issue with clang-tidy.

avogelsgesang marked an inline comment as done.

Fix CI

avogelsgesang marked an inline comment as done.Feb 27 2023, 3:37 PM
avogelsgesang added inline comments.
libcxx/include/list
2345

yes, I think so, too. Happy we have the ADL test cases nowadays!

avogelsgesang marked an inline comment as done.Feb 27 2023, 3:51 PM