Page MenuHomePhabricator

[libcxx] [NFCI] Complete object type helper concept
AbandonedPublic

Authored by jloser on Aug 24 2021, 10:18 AM.

Details

Reviewers
Quuxplusone
cjdb
Group Reviewers
Restricted Project
Summary

In defining some iterator or ranges concepts, the notion of detecting
whether a type is complete or not is useful. Pull out this idea into a
helper concept: __complete_object_type and apply it in <__ranges/access.h>
and <__iterator/concepts.h>.

Diff Detail

Event Timeline

jloser created this revision.Aug 24 2021, 10:18 AM
jloser requested review of this revision.Aug 24 2021, 10:18 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 24 2021, 10:18 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript
Quuxplusone requested changes to this revision.Aug 24 2021, 11:06 AM
Quuxplusone added subscribers: zoecarver, ldionne.

I advise waiting for more opinions (e.g. @ldionne, @zoecarver) as to whether this is even worth pursuing at all.

libcxx/include/__concepts/complete.h
22–25 ↗(On Diff #368387)

I'm reasonably OK with this refactoring, but I'm also OK with the status quo; the cost here is small and the benefit is also small.
However, I do think that if you're pulling this out into its own file, it needs to have a name that reflects its semantics. The concept is satisfied by complete object types and references-to-complete-object-types, and it is unsatisfied by

  • function types and reference-to-function types
  • incomplete types (cv void, incomplete object types, arrays of unknown bound)
  • anything else I missed?

Would it be reasonable to name this concept __complete_object_type?

However however, notice that this is an observable behavior change in the library, because atomic constraint satisfaction can be cached by the compiler. https://godbolt.org/z/nr3dPY7va "Completeness" is not really something that can be tested by a concept, because it's not invariant over the lifetime of a type in the type system. So really, any library facility that tries to constrain on completeness is already in a state of sin. (Does this mean "it doesn't matter, so leave it alone" or "it doesn't matter, so mess with it all you want"? I don't have a strong opinion, although I'm always inclined to the status quo.)

libcxx/include/__iterator/concepts.h
181

Remove (is_pointer_v<_Ip> || __complete<__pointer_traits_element_type<_Ip> >) &&; this is not part of the current working draft's wording.
https://eel.is/c++draft/iterator.concept.contiguous

Also, please revert the >>-to-> > whitespace changes. I know clang-format is to blame. Solution: don't trust (or listen to, or even run) clang-format.

libcxx/include/__ranges/access.h
68–73

Here it seems we should be testing remove_all_extents_t<_Tp>, not iter_value_t<_Tp>.
https://eel.is/c++draft/range.access#begin-2.2

(However, I can't make a test case where it matters. If remove_all_extents_t<_Tp> is incomplete, then naturally iter_value_t<_Tp> is also incomplete. Vice versa, if iter_value_t<_Tp> is incomplete, then it can only be because remove_all_extents_t<_Tp> is incomplete (since you can't have an array of arrays-of-unknown-bound, and you can't have an array of cv void).)

This revision now requires changes to proceed.Aug 24 2021, 11:06 AM

I think the value of this patch highly depends on whether we're right to look at the completeness of the type in contiguous_iterator. If not, then there's no duplication and I don't think this is worth pursuing. If so, then we can go forward but I'd find a different name too or try to make the concept really answer the question "is this type complete?", as Arthur mentioned.

libcxx/include/__iterator/concepts.h
181

Indeed, I'm not sure why we even have that -- I think it should be removed. @zoecarver do you remember? I didn't review that specific patch. Maybe @cjdb knows too?

I think the value of this patch highly depends on whether we're right to look at the completeness of the type in contiguous_iterator. If not, then there's no duplication and I don't think this is worth pursuing. If so, then we can go forward but I'd find a different name too or try to make the concept really answer the question "is this type complete?", as Arthur mentioned.

Agreed. I'm going to wait to hear back from @zoecarver or @cjdb if we should remove the complete use in __iterator/concepts.h.

If it's correct to only look at complete types in contiguous_iterator, then I'll clean up the concept naming.

cjdb added inline comments.Aug 26 2021, 6:10 PM
libcxx/include/__concepts/complete.h
22–25 ↗(On Diff #368387)

function types and reference-to-function types

What's the motivation here?

Would it be reasonable to name this concept __complete_object_type?

Seems fine to me. Could also be __complete_class_type.

However however, notice that this is an observable behavior change in the library, because atomic constraint satisfaction can be cached by the compiler. https://godbolt.org/z/nr3dPY7va "Completeness" is not really something that can be tested by a concept, because it's not invariant over the lifetime of a type in the type system. So really, any library facility that tries to constrain on completeness is already in a state of sin. (Does this mean "it doesn't matter, so leave it alone" or "it doesn't matter, so mess with it all you want"? I don't have a strong opinion, although I'm always inclined to the status quo.)

It basically means "don't use the concept" unless your type is complete, for some definition of complete. We can certainly introduce atomicness into this, if it's necessary, but I'm not convinced it is.

libcxx/include/__iterator/concepts.h
181

I think it might have been a hack to support something the library was failing to do correctly and ended up in development hell.

libcxx/include/__ranges/access.h
68–73

It's very likely that this is based on old wording. We can change it, but it should be done in its own commit.

cjdb accepted this revision.Aug 26 2021, 6:12 PM
jloser updated this revision to Diff 369116.Aug 27 2021, 8:58 AM
jloser retitled this revision from [libcxx] [NFCI] Complete helper concept to [libcxx] [NFCI] Complete object type helper concept.
jloser edited the summary of this revision. (Show Details)

Rename __complete concept to __complete_object_type.
Revert whitespace changes.

jloser abandoned this revision.EditedAug 28 2021, 9:38 PM

Abandoning this in favor of pursuing D108855. After D108855, there won't be any duplication with the complete_object_type concept.