--
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CAHtyhaSQx%3DAFWiADNthCjEMuoE5CBpVdwyGdQjCsDQSe-bYnWQ%40mail.gmail.com.
--
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CAAHOzFAOQ9OGoXE9KeK7T-KYEkdj6Lut33UtGEuqGUkYisamhg%40mail.gmail.com.
2. ranges overloads, such as a ctor or method that takes a range-concept-matching object (such as a container or view) instead of taking iterator pairs.
--
1 + 3 sgtm.2. ranges overloads, such as a ctor or method that takes a range-concept-matching object (such as a container or view) instead of taking iterator pairs.Just to clarify, do you mean range overloads provided from allowed STL types/functions or user implemented range overloads?Does the STL make use of ranges anywhere outside of <range> and range based algorithms in C++20? I see that C++23 adds range based constructors/methods to STL container types but I don't see anything like that in C++20.
Thanks for the clarification. Allowing the use of otherwise allowed STL types/functions that take a range as a parameter sgtm too.On Tue, Nov 14, 2023 at 9:38 AM Dana Jansens <dan...@chromium.org> wrote:On Tue, Nov 14, 2023 at 9:26 AM Kyle Charbonneau <kyle...@chromium.org> wrote:1 + 3 sgtm.2. ranges overloads, such as a ctor or method that takes a range-concept-matching object (such as a container or view) instead of taking iterator pairs.Just to clarify, do you mean range overloads provided from allowed STL types/functions or user implemented range overloads?Does the STL make use of ranges anywhere outside of <range> and range based algorithms in C++20? I see that C++23 adds range based constructors/methods to STL container types but I don't see anything like that in C++20.I do mean that yes, and the ones I am thinking of are in C++23, so it may not matter yet. I kinda assumed there's some in C++20. I do think it's helpful to disambiguate this from the rest though.On Mon, Nov 13, 2023 at 4:07 PM Dana Jansens <dan...@chromium.org> wrote:Hello,C++20 approval has excluded "ranges" however I want to break the ranges idea into three separate parts:1. ranges algorithms, found in the <algorithms> header: https://en.cppreference.com/w/cpp/algorithm/ranges
These algorithms depend on the concept of ranges (which we can loosely think of as containers or views with begin/end method pairs).These provide strictly better and safer APIs than the traditional iterator-pair algorithms. I am aware of no concerns with using these better algorithms. And I think we should allow them.We also model some of these in base::ranges, and we should migrate those.
2. ranges overloads, such as a ctor or method that takes a range-concept-matching object (such as a container or view) instead of taking iterator pairs.Like 1 above, these are strictly better and safer API overloads, and we should encourage their use. These are not part of "the ranges library" and are methods found on other types. So they may not have been excluded but they depend on the concept of ranges, so I think we should explicitly allow them.
3. ranges types, found in <ranges>: https://en.cppreference.com/w/cpp/header/rangesThese are new library types that provide functional/iterator-based programming primitives. There are concerns about correctness (e.g. borrowed_range is wrong for non-std view types), compile times, and legibility (e.g. with the | operator, which suffers similar problems as streams) with these types, and we should not allow them at this time.
Reviving this.Seems like we have consensus to do the following:
- Allow usage of std::ranges::xxx methods outside <ranges>:
- Algorithms in <algorithm>
- Comparison functions in <functional>
- Access functions in <iterator>
- Uninitialized storage handling in <memory>
- Once we have C++23,
- Range-constructors and range-based functions in other containers, e.g. <vector>
- Algorithms in <numeric>
- Convert usage of base::ranges::xxx to std::ranges::xxx and remove base/ranges
- Will not be fully mechanical
- Need to file a bug on this
- Specialize std::ranges::enable_borrowed_range to true for base::span to disable std::ranges::dangling for it
- Any other types we need to do this for?
- Specialize std::ranges::enable_view to true for base::span to tell range algorithms it's O(1) to construct/copy/move
- Technically y'all didn't discuss this but it seems clearly correct to me
- Any other types we need to do this for?
- Ban <ranges>
- Significant compile-time hit
- Will this still be true if we get modules?
--
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/a392900b-b702-48fb-907c-94e5f64cb4b7n%40chromium.org.
--
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/210367e4-9744-4375-a9ab-625050e45db6n%40chromium.org.
Do we know where the compiler time problems come from? Is it that the ranges header is very big, or that some particular ranges APIs cause a lot of template instantiations when used?
So, maybe I was wrong, and we should allow parts of <ranges>:
- Concepts (e.g. ranges::range)
- Primitives (e.g. ranges::iterator_t)
- Dangling iterator handling? (e.g. ranges::dangling)
- Customization point objects? (e.g. ranges::begin)
For now, I'm sure we should ban adaptors (e.g. ranges::filter_view); we should probably ban factories (e.g. ranges::iota_view); we should maybe ban views (e.g. ranges::subrange), enumerations (ranges::subrange_kind) and helpers (e.g. tuple_size<ranges::subrange>).
--
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/968fbbeb-6100-4f1d-a2ba-b9a97738a48bn%40chromium.org.
I suggesting banning subrange_kind (your #5), so I'm in agreement there. And yes, the things in #6 should be moot because we won't be using those types.PKOn Thu, May 9, 2024, 5:06 PM Daniel Cheng <dch...@chromium.org> wrote:This sounds reasonable to me, with a few minor thoughts. Just to re-enumerate what this would allow (based on filtering out what's explicitly disallowed above from cppreference):1. the various range concepts, e.g. std::ranges::borrowed_range, std::ranges::sized_range, et cetera.
2. the various range "primitives" (that's what cppreference calls it), e.g. std::ranges::range_iterator_t<R> instead of having to write decltype(std::ranges::begin(...)).
3. dangling iterators: prevents bugs like (example from cppreference):
auto get_array_by_value = [] { return std::array{0, 1, 0, 1}; };
auto dangling_iter = std::ranges::max_element(get_array_by_value());
// dangling_iter is of type std::ranges::dangling and can't be dereferenced. This is good!
I expect most 'normal' code won't really need to deal with this type directly anyway, except when there's a mistake :).
4. customization points: these seem fine, e.g. std::ranges::begin() and friends.
5. enumerations, specifically std::ranges::subrange_kind. I think we probably don't need this, given the ban on subranges and views?
6. miscellaneous helpers for subranges for std::get() and std::tuple_size and std::tuple_element.
On Thu, May 9, 2024 at 9:16 PM Peter Kasting <pkas...@chromium.org> wrote:On Thu, May 9, 2024, 5:06 PM Daniel Cheng <dch...@chromium.org> wrote:1. the various range concepts, e.g. std::ranges::borrowed_range, std::ranges::sized_range, et cetera.We should not use borrowed_range, which has the wrong default, saying ranges it does not know about are _not_ borrowed, which easily makes generic code do bad things, moving out of references. We can provide our own better one: https://chromium-review.googlesource.com/c/chromium/src/+/5166268/4/base/ranges/is_borrowed_range.h
PK
This looks like a misuse of borrowed_range to me. That concept says nothing about whether the data under the iterators can be freely modified (i.e. "no one else has a reference to this data"), which is what you'd need to write that move optimization.
It only speaks to whether you will be able to read from the iterators after the object you got them from is gone.Does the STL itself misuse this concept in this way?
--
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CAAHOzFBs7BZqi_22S7fvP-9WVNu2NGikie27WbUp9Y-h8ps19A%40mail.gmail.com.
On Wed, May 22, 2024 at 3:35 PM Peter Kasting <pkas...@chromium.org> wrote:This looks like a misuse of borrowed_range to me. That concept says nothing about whether the data under the iterators can be freely modified (i.e. "no one else has a reference to this data"), which is what you'd need to write that move optimization.The code here owns the range, so it knows through local analysis that no other code has a reference to it.
To me, that makes it a really dangerous tool that is an easy footgun.
On Wed, May 22, 2024, 12:47 PM danakj <dan...@chromium.org> wrote:On Wed, May 22, 2024 at 3:42 PM Peter Kasting <pkas...@chromium.org> wrote:On Wed, May 22, 2024, 12:40 PM danakj <dan...@chromium.org> wrote:On Wed, May 22, 2024 at 3:35 PM Peter Kasting <pkas...@chromium.org> wrote:This looks like a misuse of borrowed_range to me. That concept says nothing about whether the data under the iterators can be freely modified (i.e. "no one else has a reference to this data"), which is what you'd need to write that move optimization.The code here owns the range, so it knows through local analysis that no other code has a reference to it.It owns the range, but not the underlying data. It can't do analysis on who else might have a reference to that, and borrowed_range does not tell it that it can."The concept borrowed_range defines the requirements of a range such that a function can take it by value and return iterators obtained from it without danger of dangling."I think I am saying that if it's not borrowed, the iterators dangle because you've destroyed the owning container.I think you're saying that it's logically allowed to not dangle even though it says not-borrowed-range.Being borrowed only tells you that someone else definitely owns the backing store the iterators point into, so you can make the additional optimization of dropping the range early instead of having to keep it alive past any calls using the iterators. But it doesn't tell you about the data within that store. Even if the type is not a borrowed range, maybe the range holds a ref to the data, so the type alone does not tell you whether anyone else can access this data. Maybe the iterators came transitively from another source, so this type cannot guarantee their provenance.The intent is that "borrowed" is the optimizable case, rather than "not borrowed". What you're looking for sounds a bit more like "is a sole ownership type".
To me, that makes it a really dangerous tool that is an easy footgun.I don't know that I agree. It doesn't have the sort of subtle action at a distance that [[no_unique_address]] does. It's simply meant for a single narrow optimization case: if the range borrows, you can drop it once you've gotten the iterators.
PK
Maybe the important thing for this thread is just concluding whether we need to ban/rewrite anything related to borrowed ranges. I don't think we do, we just need to be narrow in our use of that concept to optimize. Do you agree?
--
You received this message because you are subscribed to a topic in the Google Groups "cxx" group.
To unsubscribe from this topic, visit https://groups.google.com/a/chromium.org/d/topic/cxx/ZnIbkfJ0Glw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to cxx+uns...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CAHtyhaQjfG%2BvqTsMz7gZO7c08x%2B%2B%3DdfSJYJY1rtkvT1sw_op-Q%40mail.gmail.com.