[llvm-dev] RFC: [SmallVector] Adding SVec<T> and Vec<T> convenience wrappers.

Chris Lattner via llvm-dev llvm-dev at lists.llvm.org
Sat Dec 5 11:59:57 PST 2020


> On Dec 5, 2020, at 10:46 AM, David Blaikie <dblaikie at gmail.com> wrote:
> I think I see what you’re going for here, and I agree that std::string is a slightly different situation than std::vector given that some implementations have a small string optimizations already.
> 
> I feel like you’re prioritizing the iterator invalidation behavior as the core difference between the two types, whereas I’m prioritizing the performance/allocation-behavior aspect.  I feel like this is a major difference in practice that API users should think about, and they should be prepared to deal with the iterator invalidation issues as necessary.
> 
> Is the "Reduced sizeof(t) and guaranteed iterator validity over swap/move (ie: must not use an inline buffer)” use case important enough to have a “string-y” type?
> 
> I think things got confused again - reduced sizeof/guaranteed iterator validity isn't a string-y type (because of the iterator validity guarantee such a type can't use an inline buffer - unlike std::string), it's what we're talking about/potentially calling llvm::Vector.

Ok, I thought you were talking about bringing that idea to string-y types because std::string doesn’t provide it..
 
>  As you say, we don’t have a solution for this in the current code other than std::vector.  I haven’t heard of this being a significant enough problem to be worth “fixing”, and I don’t think we can drop the inline vs out-of-line distinction.
> 
> Hmm - I think I'm still miscommunicating/not making sense.
> 
> I think there's value in having a type that has a guarantee of no-inline-storage - when you want to move and maintain iterator validity.

Right, in the vector domain, this is the llvm::Vector type(def).

> But I'm wondering if the type with possibly using inline storage could be thought of more like std::string (ie: define the contract: iterators invalidated on move) rather than like SmallVector (ie: "must have an inline buffer"). I don't know what we would call this thing - but my point is to try to move away from the name dictating the implementation detail of having an inline buffer (we could still have SmallVector<T, N> for when you specifically want an inline buffer) but OtherThingVector<T> would not require an inline buffer it would be "a type without iterator validity on move that has, or doesn't have, an inline buffer as it chooses to based on performance tradeoffs".
> 
> I think, to me, this would be better than "SmallVector<T> must have at least 1 inline element because of the word "Small" in the name" if we moved away from having Small in the name, and towards some sense of the contract & leaving the implementation to make the choice of how to best implement that contract.
> 
> But I think I'm going around in circles/not necessarily making sense here. Perhaps a chat on discord or something would be more effective?

I think I understand what you’re saying: you’re focusing on making iterator invalidation semantics primary instead of memory layout.  This is a reasonable thing to do, but I don’t think we should go with a design that ignores the “in place ness”.  Maybe there is a “best of both worlds” design proposal that could make sense here?

> The difference I meant was that it forwards transparently to array_pod_sort / qsort which is a pretty big behavioral difference.
> 
> Ah, more llvm::sort(iter, iter) - yeah, hadn't thought about that one. Different performance characteristics, but the same contract, right? So this is working around sub-optimal standard library implementations, but not providing a different contract/requirements, is it?

It’s really a “similar but different” API.  I works the same in the easy cases, but doesn’t have the same set of contracts, that was my only analogy.   There are lots of other APIs that are similar-but-different in innumerable ways that provide tradeoffs e.g. DenseMap vs std::map, etc.  The programmer’s manual has a long list of options :-)

-Chris


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20201205/36cf4429/attachment.html>


More information about the llvm-dev mailing list