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>.
Details
- Reviewers
• Quuxplusone cjdb - Group Reviewers
Restricted Project
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
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 | 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.
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 | ||
178 | Remove (is_pointer_v<_Ip> || __complete<__pointer_traits_element_type<_Ip> >) &&; this is not part of the current working draft's wording. 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 | ||
67–73 | Here it seems we should be testing remove_all_extents_t<_Tp>, not iter_value_t<_Tp>. (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).) |
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 | ||
---|---|---|
178 | 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? |
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.
libcxx/include/__concepts/complete.h | ||
---|---|---|
22–25 |
What's the motivation here?
Seems fine to me. Could also be __complete_class_type.
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 | ||
178 | 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 | ||
67–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. |
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
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.)