This is an archive of the discontinued LLVM Phabricator instance.

[libc++] Don't warn that coroutines aren't supported when including <experimental/coroutine>
ClosedPublic

Authored by philnik on Feb 16 2022, 11:34 AM.

Details

Summary

This change makes the behavior of <experimental/coroutine> consistent with other headers that only work conditionally.

Diff Detail

Event Timeline

philnik created this revision.Feb 16 2022, 11:34 AM
philnik requested review of this revision.Feb 16 2022, 11:34 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 16 2022, 11:34 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript
Quuxplusone requested changes to this revision.Feb 16 2022, 12:08 PM

No, that definitely shouldn't be the case. There's no need to #include <__config> before #include <algorithm>, because <algorithm> itself includes <__config>.
(And there's no need for <algorithm> to include <__config> before including <__algorithm/adjacent_find.h>, because <__algorithm/adjacent_find.h> itself includes <__config>! And so on.)

This revision now requires changes to proceed.Feb 16 2022, 12:08 PM

No, that definitely shouldn't be the case. There's no need to #include <__config> before #include <algorithm>, because <algorithm> itself includes <__config>.
(And there's no need for <algorithm> to include <__config> before including <__algorithm/adjacent_find.h>, because <__algorithm/adjacent_find.h> itself includes <__config>! And so on.)

The problem is that we use macros from <__config>. This means that we might include a header that shouldn't be included. Just as an example, maybe we want to remove <experimental/algorithm>. That means that the first include in the list is conditionally included, but the header where the condition is set isn't included before the condition is checked. That means <experimental/coroutine> is always included, but might not be available in a configuration.

Quuxplusone added inline comments.
libcxx/test/libcxx/clang_tidy.sh.cpp
208–212 ↗(On Diff #409347)

No, that definitely shouldn't be the case. There's no need to #include <__config> before #include <algorithm>, because <algorithm> itself includes <__config>.
(And there's no need for <algorithm> to include <__config> before including <__algorithm/adjacent_find.h>, because <__algorithm/adjacent_find.h> itself includes <__config>! And so on.)

The problem is that we use macros from <__config>. This means that we might include a header that shouldn't be included. Just as an example, maybe we want to remove <experimental/algorithm>. That means that the first include in the list is conditionally included, but the header where the condition is set isn't included before the condition is checked. That means <experimental/coroutine> is always included, but might not be available in a configuration.

Aha, I see. So there's no problem today, but there will be a problem as soon as you git rm experimental/algorithm, because then the first header in the list of experimental headers (alphabetically) will be one that it's not always safe to include.

I guess my next question is, why is it unsafe to unconditionally include <experimental/coroutine>? So I looked at the top of that file and found

#ifdef _LIBCPP_HAS_NO_EXPERIMENTAL_COROUTINES
# if defined(_LIBCPP_WARNING)
    _LIBCPP_WARNING("<experimental/coroutine> cannot be used with this compiler")
# else
#   warning <experimental/coroutine> cannot be used with this compiler
# endif
#endif

Perhaps we should replace this with our usual convention, which is just to make the whole file a no-op if it's not supported. (<coroutine> uses our usual convention, because it was written more recently.) @ldionne @ChuanqiXu, thoughts?

Mordante added inline comments.
libcxx/test/libcxx/clang_tidy.sh.cpp
208–212 ↗(On Diff #409347)

Perhaps we should replace this with our usual convention, which is just to make the whole file a no-op if it's not supported. (<coroutine> uses our usual convention, because it was written more recently.) @ldionne @ChuanqiXu, thoughts?

In the release notes we mentioned <experimental/coroutine> will be removed in LLVM 15. So maybe removing this header now will be a better solution.

philnik added inline comments.Feb 17 2022, 1:13 PM
libcxx/test/libcxx/clang_tidy.sh.cpp
208–212 ↗(On Diff #409347)

It would probably be a good idea. I'll put it on my TODO-list. I still think it's a good idea to add the <__config> includes to make sure we have all the macros before we check if they are defined.

ChuanqiXu added inline comments.Feb 17 2022, 10:15 PM
libcxx/test/libcxx/clang_tidy.sh.cpp
208–212 ↗(On Diff #409347)

Personally, I prefer to diagnostic early if we detected user are doing the wrong behavior. But given that consistency is very important in projects like libcxx, I agree we should follow the usual convention to make it a no-op.

ldionne requested changes to this revision.Mar 3 2022, 6:42 AM

I believe we should make <experimental/coroutine> empty instead of issuing a #warning when coroutines are disabled. That will solve this problem and be consistent with what we do everywhere else.

libcxx/test/libcxx/clang_tidy.sh.cpp
208–212 ↗(On Diff #409347)

In the release notes we mentioned <experimental/coroutine> will be removed in LLVM 15. So maybe removing this header now will be a better solution.

The note I have locally says LLVM 16. We shipped <coroutine> in LLVM 14, which means that we remove <experimental/coroutines> in LLVM 16. Please correct me if I'm mistaken.

Herald added a project: Restricted Project. · View Herald TranscriptMar 3 2022, 6:42 AM
philnik updated this revision to Diff 412796.Mar 3 2022, 11:49 AM
philnik marked 4 inline comments as done.
  • Don't warn in <experimental/coroutine>
philnik retitled this revision from [libc++] Generated headers should first include <__config> to [libc++] Don't warn that coroutines aren't supported when including <experimental/coroutine>.Mar 3 2022, 11:50 AM
philnik updated this revision to Diff 412797.Mar 3 2022, 11:52 AM

Only upload the new diff

ldionne accepted this revision.Mar 3 2022, 12:19 PM

Please make sure your commit message explains why you're doing this -- otherwise someone looking at the history would be rather puzzled (at first glance, this appears to be removing something useful).

philnik edited the summary of this revision. (Show Details)Mar 3 2022, 12:41 PM
Mordante added inline comments.Mar 3 2022, 12:56 PM
libcxx/test/libcxx/clang_tidy.sh.cpp
208–212 ↗(On Diff #409347)

As discussed on Discord I thought it was LLVM 15 and added that version in the release notes. The release notes have been updated in D120935.

This revision was not accepted when it landed; it landed in state Needs Review.Mar 5 2022, 10:01 AM
This revision was automatically updated to reflect the committed changes.