This is an archive of the discontinued LLVM Phabricator instance.

[libc++] Implement P1169R4 (static operator())
ClosedPublic

Authored by philnik on Oct 1 2022, 12:27 PM.

Diff Detail

Event Timeline

philnik created this revision.Oct 1 2022, 12:27 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 1 2022, 12:27 PM
philnik requested review of this revision.Oct 1 2022, 12:27 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 1 2022, 12:27 PM
Herald added a reviewer: Restricted Project. · View Herald Transcript
EricWF requested changes to this revision.Oct 1 2022, 7:37 PM
EricWF added a subscriber: EricWF.

this needs real tests. compile only tests are not sufficient

This revision now requires changes to proceed.Oct 1 2022, 7:37 PM

this needs real tests. compile only tests are not sufficient

Why? CTAD is a compile-time feature. There is no runtime to test.

Are the packaged_task changes intentionally missing? I haven't found any deduction guides in source for packaged_task so maybe they're implicit somehow and I miss it.

this needs real tests. compile only tests are not sufficient

Why? CTAD is a compile-time feature. There is no runtime to test.

Because people run their code sometimes. And we should too.
And because writing holistic tests catches more than just bugs in the change.
They can catch compiler frontend and backend bugs, latent bugs in existing code, etc.

Because shipping a bug in libc++ is such a high cost, it's worth it to test more than the bare minimum.

Yes, it deduces to the correct type. But does it correctly call the constructor and store the pointer? It should, but does it?

ldionne requested changes to this revision.Oct 4 2022, 10:22 AM

More generally speaking, I think Eric's point is that we should also add tests that ensure that std::function works with a static operator(), regardless of CTAD. I agree with that, however I can see why that could be seen as separate from this patch.

But yes, I think we should definitely have runtime tests to check the interaction of static operator() and std::function.

libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/ctad.static.compile.pass.cpp
10

Why do we support this pre-C++23?

philnik updated this revision to Diff 465735.Oct 6 2022, 7:55 AM
  • Address comments

Are the packaged_task changes intentionally missing? I haven't found any deduction guides in source for packaged_task so maybe they're implicit somehow and I miss it.

No, I just missed them somehow. It also seems that we don't have CTAD implemented for packaged_task yet, so I did it here.

More generally speaking, I think Eric's point is that we should also add tests that ensure that std::function works with a static operator(), regardless of CTAD. I agree with that, however I can see why that could be seen as separate from this patch.

But yes, I think we should definitely have runtime tests to check the interaction of static operator() and std::function.

I would consider this a separate issue, since there are probably other areas where we want to add static operator() tests.

libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/ctad.static.compile.pass.cpp
10

Because my plan is to use static operator() for the implementation of the ranges algorithms, since it improves code gen.

ldionne accepted this revision.Oct 6 2022, 8:41 AM

This LGTM with my comments.

libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/ctad.static.compile.pass.cpp
10

Range algorithms can't be passed to std::function if we follow the letter of the standard. I don't think we should attempt to support this before C++23. If we do, then we are almost certainly missing similar things elsewhere in the library, which would make our support for that spotty anyway.

Let's just implement this in C++23, as specified, and we can make our ranges algorithms' operator() static, which shouldn't be detectable. While people can technically detect it by looking at the type of e.g. std::ranges::copy::operator(), they are not allowed to do that in the first place, which makes this undetectable.

19

Let's mark this as UNSUPPORTED: clang-14, clang-15, gcc-12 instead.

21

Please add a few more cases: 0 arguments, 1 argument, variadic arguments, default argument (why not?).

Also, let's run these tests (not compile only), unless you sign up to address the more general issue of testing the integration of static operator() in std::function (and probably other places). If you don't sign up for that, then let's run these tests cause that's going to be better than nothing.

huixie90 accepted this revision.Oct 8 2022, 7:38 AM
huixie90 added inline comments.
libcxx/include/__functional/function.h
1122–1123

Should this be C++23?

libcxx/include/future
2053 ↗(On Diff #465735)

Should the new deduction guide be C++23?

philnik updated this revision to Diff 470297.Oct 24 2022, 2:57 PM
philnik marked 6 inline comments as done.
  • Rebased
  • Address comments
  • Try to fix CI
libcxx/include/__functional/function.h
1122–1123

No, this has been added in C++17.

libcxx/include/future
2053 ↗(On Diff #465735)

No, this is from LWG3117, which IIUC should be applied retroactively to C++17.

libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/ctad.static.compile.pass.cpp
19

I'm XFAILing it to ensure we test it on all compilers that support static operator().

21

I'd rather do it not at all or properly, than half-assed, so I guess I'm signing up for it. Otherwise it probably happens in 5 years.

philnik updated this revision to Diff 481888.Dec 10 2022, 5:04 PM

Try to fix CI

philnik updated this revision to Diff 482965.Dec 14 2022, 12:46 PM

Try to fix CI

This revision was not accepted when it landed; it landed in state Needs Review.Dec 14 2022, 5:19 PM
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.