This is an archive of the discontinued LLVM Phabricator instance.

[libc++] Remove the chrono include from algorithm
ClosedPublic

Authored by iana on Apr 14 2023, 5:52 PM.

Details

Reviewers
ldionne
Mordante
Group Reviewers
Restricted Project
Commits
rG1eb74f7e83ff: [libc++] Remove the chrono include from algorithm
Summary

algorithm's include of chrono causes include cycles:

algorithm -> chrono -> __chrono/convert_to_tm.h -> __chrono/statically_widen.h -> __format/concepts.h -> __format/format_parse_context.h -> string_view -> algorithm

algorithm -> chrono -> __chrono/convert_to_tm.h -> __chrono/statically_widen.h -> __format/concepts.h -> __format/format_parse_context.h -> string_view -> functional -> __functional/boyer_moore_searcher.h -> array -> algorithm

algorithm -> chrono -> __chrono/convert_to_tm.h -> __chrono/statically_widen.h -> __format/concepts.h -> __format/format_parse_context.h -> string_view -> functional -> __functional/boyer_moore_searcher.h -> unordered_map -> algorithm

algorithm -> chrono -> __chrono/convert_to_tm.h -> __chrono/statically_widen.h -> __format/concepts.h -> __format/format_parse_context.h -> string_view -> functional -> __functional/boyer_moore_searcher.h -> vector -> algorithm

This is a problem for clang modules after the std mega module is broken up, because it becomes a module cycle which is a hard error.

All of the includes in the __chrono and __format headers are being used and so can't be removed. algorithm's include of chrono is already removed in C++20, whereas the array, string_view, unordered_map, vector includes of algorithm aren't removed until C++23 (and it's 4x the includes that would need removing). Unconditionally remove the chrono include from algorithm in all versions, so that the module breakup can happen (the module has to apply to all C++ versions).

Diff Detail

Event Timeline

iana created this revision.Apr 14 2023, 5:52 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 14 2023, 5:52 PM
Herald added a subscriber: ributzka. · View Herald Transcript
iana requested review of this revision.Apr 14 2023, 5:52 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 14 2023, 5:52 PM
Herald added a reviewer: Restricted Project. · View Herald Transcript
iana edited the summary of this revision. (Show Details)Apr 14 2023, 5:53 PM
iana edited the summary of this revision. (Show Details)
Mordante requested changes to this revision.Apr 15 2023, 5:08 AM

Interesting that it fails with modules. In general we keep these transitive includes to avoid possibly breaking user code that depends on these transitive includes. (Note it's a bug in the user's code to depend on these includes, but this is not easily spotted.) However when it block us we are free to remove them. So no objection to the removal.

I expect this to fail in the CI since the transitive includes are not updated. Let me know if you need help with this.

This change needs to be mentioned in our release notes (docs/ReleaseNotes.rst) since it may affect users.

This revision now requires changes to proceed.Apr 15 2023, 5:08 AM
iana updated this revision to Diff 513936.Apr 15 2023, 1:30 PM

Remove algorithm -> chrono from the transitive include tests. Add a release note saying the include was removed and why.

iana added a comment.Apr 15 2023, 1:30 PM

Interesting that it fails with modules. In general we keep these transitive includes to avoid possibly breaking user code that depends on these transitive includes. (Note it's a bug in the user's code to depend on these includes, but this is not easily spotted.) However when it block us we are free to remove them. So no objection to the removal.

I expect this to fail in the CI since the transitive includes are not updated. Let me know if you need help with this.

This change needs to be mentioned in our release notes (docs/ReleaseNotes.rst) since it may affect users.

I'm not sure what I'm doing wrong, but check-cxx doesn't complain about the removed include. If I take algorithm -> chrono out of the csv files it also doesn't complain.

Interesting that it fails with modules. In general we keep these transitive includes to avoid possibly breaking user code that depends on these transitive includes. (Note it's a bug in the user's code to depend on these includes, but this is not easily spotted.) However when it block us we are free to remove them. So no objection to the removal.

I expect this to fail in the CI since the transitive includes are not updated. Let me know if you need help with this.

This change needs to be mentioned in our release notes (docs/ReleaseNotes.rst) since it may affect users.

I'm not sure what I'm doing wrong, but check-cxx doesn't complain about the removed include. If I take algorithm -> chrono out of the csv files it also doesn't complain.

Check-cxx needs to be executed for every language version. If you intend to do more of these cleanups I can explain what to do. If it's only one it's easier for me to commandeer the revision and apply the fixes.

libcxx/docs/ReleaseNotes.rst
70–71

In the release notes we usually give no rationale.

iana updated this revision to Diff 514270.Apr 17 2023, 9:24 AM

Remove the rationale for removing algorithm -> chrono from the release notes.

iana marked an inline comment as done.Apr 17 2023, 9:24 AM

Interesting that it fails with modules. In general we keep these transitive includes to avoid possibly breaking user code that depends on these transitive includes. (Note it's a bug in the user's code to depend on these includes, but this is not easily spotted.) However when it block us we are free to remove them. So no objection to the removal.

I expect this to fail in the CI since the transitive includes are not updated. Let me know if you need help with this.

This change needs to be mentioned in our release notes (docs/ReleaseNotes.rst) since it may affect users.

I'm not sure what I'm doing wrong, but check-cxx doesn't complain about the removed include. If I take algorithm -> chrono out of the csv files it also doesn't complain.

Check-cxx needs to be executed for every language version. If you intend to do more of these cleanups I can explain what to do. If it's only one it's easier for me to commandeer the revision and apply the fixes.

Ah. This was the only pure include cycle I found, but it's possible there will be some module cycles that still need to be broken up. It'd be good for me to know how to run it properly anyway, but also feel free to commandeer if you prefer.

Interesting that it fails with modules. In general we keep these transitive includes to avoid possibly breaking user code that depends on these transitive includes. (Note it's a bug in the user's code to depend on these includes, but this is not easily spotted.) However when it block us we are free to remove them. So no objection to the removal.

I expect this to fail in the CI since the transitive includes are not updated. Let me know if you need help with this.

This change needs to be mentioned in our release notes (docs/ReleaseNotes.rst) since it may affect users.

I'm not sure what I'm doing wrong, but check-cxx doesn't complain about the removed include. If I take algorithm -> chrono out of the csv files it also doesn't complain.

Check-cxx needs to be executed for every language version. If you intend to do more of these cleanups I can explain what to do. If it's only one it's easier for me to commandeer the revision and apply the fixes.

Ah. This was the only pure include cycle I found, but it's possible there will be some module cycles that still need to be broken up. It'd be good for me to know how to run it properly anyway, but also feel free to commandeer if you prefer.

Actually the method is described in libcxx/test/libcxx/transitive_includes.sh.cpp:45 re-generating the files is done by building the target libcxx-generate-files.

iana updated this revision to Diff 514720.Apr 18 2023, 12:51 PM

Fix a test failure

iana updated this revision to Diff 515073.Apr 19 2023, 1:36 PM

Fix another test failure.

iana updated this revision to Diff 515212.Apr 19 2023, 9:39 PM

Fixed more tests

iana added a comment.Apr 20 2023, 10:17 AM

Interesting that it fails with modules. In general we keep these transitive includes to avoid possibly breaking user code that depends on these transitive includes. (Note it's a bug in the user's code to depend on these includes, but this is not easily spotted.) However when it block us we are free to remove them. So no objection to the removal.

I expect this to fail in the CI since the transitive includes are not updated. Let me know if you need help with this.

This change needs to be mentioned in our release notes (docs/ReleaseNotes.rst) since it may affect users.

I'm not sure what I'm doing wrong, but check-cxx doesn't complain about the removed include. If I take algorithm -> chrono out of the csv files it also doesn't complain.

Check-cxx needs to be executed for every language version. If you intend to do more of these cleanups I can explain what to do. If it's only one it's easier for me to commandeer the revision and apply the fixes.

Ah. This was the only pure include cycle I found, but it's possible there will be some module cycles that still need to be broken up. It'd be good for me to know how to run it properly anyway, but also feel free to commandeer if you prefer.

Actually the method is described in libcxx/test/libcxx/transitive_includes.sh.cpp:45 re-generating the files is done by building the target libcxx-generate-files.

Thanks, I think I got the tests all squared away. I'm not sure what's up with the sanitizer and aix failures, but they don't look related to this change I think. (I'm not even sure the transitive include failures about thread missing cstdlib are related to this, but I needed those tests to pass and it looks reasonable that thread includes cstdlib.)

Mordante accepted this revision.Apr 21 2023, 11:03 AM

Interesting that it fails with modules. In general we keep these transitive includes to avoid possibly breaking user code that depends on these transitive includes. (Note it's a bug in the user's code to depend on these includes, but this is not easily spotted.) However when it block us we are free to remove them. So no objection to the removal.

I expect this to fail in the CI since the transitive includes are not updated. Let me know if you need help with this.

This change needs to be mentioned in our release notes (docs/ReleaseNotes.rst) since it may affect users.

I'm not sure what I'm doing wrong, but check-cxx doesn't complain about the removed include. If I take algorithm -> chrono out of the csv files it also doesn't complain.

Check-cxx needs to be executed for every language version. If you intend to do more of these cleanups I can explain what to do. If it's only one it's easier for me to commandeer the revision and apply the fixes.

Ah. This was the only pure include cycle I found, but it's possible there will be some module cycles that still need to be broken up. It'd be good for me to know how to run it properly anyway, but also feel free to commandeer if you prefer.

Actually the method is described in libcxx/test/libcxx/transitive_includes.sh.cpp:45 re-generating the files is done by building the target libcxx-generate-files.

Thanks, I think I got the tests all squared away. I'm not sure what's up with the sanitizer and aix failures, but they don't look related to this change I think. (I'm not even sure the transitive include failures about thread missing cstdlib are related to this, but I needed those tests to pass and it looks reasonable that thread includes cstdlib.)

The AIX and sanitizers are unrelated. The cstdlib is related. I know it's not always clear. Before cstdlib was indirectly provided by chrono and not listed. Removing that include causes it to be attributed by a different header providing it to thread. I know this can be a bit confusion to people unfamiliar with it.

Thanks for the fixes, LGTM!

This revision is now accepted and ready to land.Apr 21 2023, 11:03 AM
This revision was landed with ongoing or failed builds.Apr 22 2023, 11:31 AM
This revision was automatically updated to reflect the committed changes.