This is an archive of the discontinued LLVM Phabricator instance.

[libc++] implement move_iterator<T*> should be a random access iterator
AbandonedPublic

Authored by Mordante on Oct 5 2022, 1:33 AM.

Diff Detail

Event Timeline

phyBrackets created this revision.Oct 5 2022, 1:33 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 5 2022, 1:33 AM
phyBrackets requested review of this revision.Oct 5 2022, 1:33 AM
Herald added a reviewer: Restricted Project. · View Herald TranscriptOct 5 2022, 1:33 AM

I'm not sure about, where to look for testing of it or need to create new tests ?

philnik requested changes to this revision.Oct 5 2022, 5:02 AM

I'm not sure about, where to look for testing of it or need to create new tests ?

There should be a test in libcxx/test/std/iterators/predef.iterators/move.iterators/move.iterator.

Please go through https://libcxx.llvm.org/Contributing.html#pre-commit-check-list again and check that you did everything.

libcxx/include/__iterator/move_iterator.h
72

You can make this function consteval. IMO Something like __get_iterator_concept() would be clearer, since iterator tags are used for both iterator_category and iterator_concept, but this function is only correct for iterator_concept. You also have to guard the functions with _LIBCPP_STD_VER >= 20.

73

The paper is referencing C++20 iterators, not C++17 iterators.

77

You have to check bidirectional_iterator before forward_iterator, since random_access_iterator is a subset of bidirectional_iterator is a subset of forward_iterator.

This revision now requires changes to proceed.Oct 5 2022, 5:02 AM
huixie90 requested changes to this revision.Oct 5 2022, 5:05 AM
huixie90 added a subscriber: huixie90.

Thanks for the patch. Please take a look at the test
libcxx/test/std/iterators/predef.iterators/move.iterators/move.iterator/types.pass.cpp
and update it, and/or add new tests

Another question is it this paper a DR or not? do we want to DR back to C++20's or just for C++23?

libcxx/include/__iterator/move_iterator.h
72

either add _LIBCPP_HIDE_FROM_ABI macro, or change the function to consteval

73–77

According to p2520r0, these checks should check against C++20 concept rather than C++17 concepts

if constexpr (random_access_iterator<_Iter>){
 // ...
} else if constexpr (bidirectional_iterator<_Iter>) {
 // ...
} else if constexpr ( forward_iterator<_Iter>) {

And then the function should be guarded against C++ 20

75

forward_iterator check should come after bidirectional_iterator

phyBrackets added inline comments.Oct 5 2022, 6:52 AM
libcxx/include/__iterator/move_iterator.h
72

doesn't _LIBCPP_STD_VER > 17 means the same?

philnik added inline comments.Oct 5 2022, 7:09 AM
libcxx/include/__iterator/move_iterator.h
72

Yes, but you didn't guard the function at all. We also decided to switch to _LIBCPP_STD_VER >= xy in new code.

phyBrackets marked 6 inline comments as done.Oct 5 2022, 8:13 AM

Hey @philnik , could you tell me about the tests? does changes in the type.pass.cpp looks correct? Although I tried running the test using llvm-lit but got the failure on iterator_concept_conformance.compile.pass.cpp and type.pass.cpp.

Re-uploading the patch

Updating the patch after rebasing

This patch isn't on top of main, is it?

phyBrackets set the repository for this revision to rG LLVM Github Monorepo.

rebase the changes on top of main

EricWF requested changes to this revision.Nov 7 2022, 10:57 AM
EricWF added a subscriber: EricWF.
EricWF added inline comments.
libcxx/include/__iterator/move_iterator.h
71

As others have said _LIBCPP_STD_VER > 20

72

Yeah, this doesn't need _LIBCPP_HIDE_FROM_ABI, but if you want it for consistency...

In fact we don't need to hide 70% of the stuff we hide, but /shrug

72

Reserved names are __lower_case_after_two_underscores or _UpperCaseAfterOneUnderscore.

You either need two underscores or a single underscore followed by a capital letter.

84

Why did this stuff get moved?

libcxx/test/std/iterators/predef.iterators/move.iterators/move.iterator/types.pass.cpp
144–145

This is the correct behavior for C++20, the change only applies to C++2b.
So don't change these tests, but instead add more tests for the new C++20 behavior.

This revision now requires changes to proceed.Nov 7 2022, 10:57 AM
phyBrackets added inline comments.Nov 7 2022, 11:48 PM
libcxx/test/std/iterators/predef.iterators/move.iterators/move.iterator/types.pass.cpp
144–145

shouldn't it be for _LIBCPP_STD_VER >= 20 ?

update the revision with few changes for the correct version

phyBrackets marked 3 inline comments as done.Nov 8 2022, 1:48 AM
phyBrackets added inline comments.
libcxx/include/__iterator/move_iterator.h
84

__get_iterator_concept and _Iter __current_ both of them are the private members, so I thought we can place them together. but yeah i guess it's fine to place separately.

phyBrackets marked an inline comment as done.

Hey @EricWF , could you please take a look at this patch, i guess there are some tests which got affected by this . I'm not sure if i need to update them for passing the CI?

Hey @EricWF , could you please take a look at this patch, i guess there are some tests which got affected by this . I'm not sure if i need to update them for passing the CI?

It looks to me that there are still issues with this patch changing the implementation prior to C++20. Please fix that (see the existing inline comments).

Correctly places the macros.

It still failing on the ranges.min.max.pass.cpp, we need to guard that too for passing the CI. Or Is there any other work around?

Hi.

I started https://reviews.llvm.org/D142841 because I missed your revision.

I abadonned my revision.

I think you need to do such changes that I did in:

libcxx/docs/ReleaseNotes.rst

libcxx/docs/Status/Cxx2bPapers.csv

libcxx/include/iterator

Feel free to use my revision.

libcxx/test/std/iterators/predef.iterators/move.iterators/move.iterator/types.pass.cpp
19
fsb4000 added a comment.EditedJan 29 2023, 9:02 PM

libcxx/test/std/algorithms/alg.sorting/alg.min.max/ranges.minmax.pass.cpp failed because of a bug in our ranges::minmax implementation.

I will prepare a fix in few minutes.

For an update on the patch, this patch is currently for _LIBCPP_STD_VER > 20 , and tests cases fixed accordingly to pass the CI , if there is anything that needs to be change, let me know!

Please remove the format-only changes. This makes it incredibly hard to see what you actually changed.

Hey @philnik , sorry for the format changes but this is what i can do best for now , not sure about the removing all the format changes!

for ignoring the whitespace changes used git diff -b that's why it's failing for now but will change it once you review the basic structure of the patch

I pushed my commit: https://github.com/llvm/llvm-project/commit/0a0d58f5465a2524ec9ed10ed0bb277cab5a180c

Now you have to rebase your patch and then you don't need

#if TEST_STD_VER <= 20
...
#endif

in ranges.minmax.pass.cpp

Actually that code block was removed at all.

fsb4000 added a comment.EditedFeb 17 2023, 8:19 AM

patch application failed

How did you create your diff?
I create my diffs like this:

git diff -U999999 main > 1.txt

and then I upload 1.txt

Herald added a project: Restricted Project. · View Herald TranscriptFeb 17 2023, 10:04 AM

patch application failed

How did you create your diff?
I create my diffs like this:

git diff -U999999 main > 1.txt

and then I upload 1.txt

Thanks @fsb4000 , missed the main

Build 327893: pre-merge checks patch application failed

Could you upload your branch to your github? (https://github.com/phyBrackets/llvm-project-1)

I will try to generate the correct diff.

Thanks, I see something really cursed happened.

https://github.com/phyBrackets/llvm-project-1/tree/newB

This branch is 2972 commits ahead, 3044 commits behind llvm:main.

You could try upload my 1.txt file as a revision, maybe we can progress this way...

fsb4000 added inline comments.Feb 26 2023, 8:48 AM
libcxx/docs/FeatureTestMacroTable.rst
263

CI failed because extra space there

phyBrackets marked an inline comment as done.
fsb4000 accepted this revision.Feb 26 2023, 3:53 PM

Microsoft STL treats this paper as a DR and I agree with Casey Carter that the code breakage will be minimal because the move_iterators are still input iterators in C++20.

libc++ already gives more guaranties for things than the standard says, for example for the 'std::filesystem::path::iterator'.

from https://github.com/microsoft/STL/pull/2958#discussion_r931710527

This paper is effectively an admission that artificially depressing the category of move_iterator was a failed experiment. There's no value in preserving the undesired behavior in C++20 mode, and we suspect the potential for breakage to be very small given that move_iterators are still input iterators even if they now sometimes satisfy stronger concepts. We therefore decided to implement this change in all pertinent language modes.

What do other reviewers think?

@jwakely Does libstdc++ implement P2520R0 in C++20 as a DR too?

My desire here is to align the various implementations.

@jwakely Does libstdc++ implement P2520R0 in C++20 as a DR too?

We didn't implement this yet, but Casey's position makes sense to me.

I'm happy to do this for C++20 if you are doing it.

Hey @fsb4000 @ldionne , Let me know if it's fine to commit this. I'll do it. Thanks!

philnik accepted this revision.Mar 1 2023, 8:21 AM

LGTM % comments.

libcxx/docs/ReleaseNotes.rst
40–41 ↗(On Diff #500594)
libcxx/test/std/iterators/predef.iterators/move.iterators/move.iterator/types.pass.cpp
102

Hey @philnik , I'm not sure about, can we land this now?

Hey @philnik , I'm not sure about, can we land this now?

With the remaining comments address we can land it.

cool, Thanks!

@jwakely Does libstdc++ implement P2520R0 in C++20 as a DR too?

We didn't implement this yet, but Casey's position makes sense to me.

I'm happy to do this for C++20 if you are doing it.

Ok, let's all do it then.

@phyBrackets Can you please add the note in another PR? This was committed sooner than I expected.

libcxx/docs/Status/Cxx2bPapers.csv
87 ↗(On Diff #500594)

Please add a note that we implement P2520R0 as a DR in C++20 as well.

FYI it seems that commit message does have a slightly different

Differntial Revision- https://reviews.llvm.org/D135248

part in the message. Please use the proper form next time, then Phabricator will automatically close the revision.

Can you close it manually?

Hey @Mordante , Sorry for it! I'm not sure how to close it manually, I tried Add Action here but I cannot see any option for Closing the revision ?

Mordante commandeered this revision.Mar 1 2023, 12:30 PM
Mordante added a reviewer: phyBrackets.

Hey @Mordante , Sorry for it! I'm not sure how to close it manually, I tried Add Action here but I cannot see any option for Closing the revision ?

Odd, I'll try it by taking over the patch.

Mordante abandoned this revision.Mar 1 2023, 12:32 PM

Odd I don't see close too, I'll mark it as abandoned, that way it will be marked as closed.