Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upImplement placement-in protocol for `Vec` #32366
Conversation
rust-highfive
assigned
brson
Mar 20, 2016
This comment has been minimized.
This comment has been minimized.
|
r? @brson (rust_highfive has picked a reviewer for you, use r? to override) |
petrochenkov
reviewed
Mar 20, 2016
| ptr::write(end, value); | ||
| self.len += 1; | ||
| } | ||
| self <- value; |
This comment has been minimized.
This comment has been minimized.
petrochenkov
Mar 20, 2016
Contributor
I'd avoid using placement in stable push before doing proper performance measurements.
This comment has been minimized.
This comment has been minimized.
nagisa
Mar 20, 2016
Contributor
I had some benchmarks implemented in nagisa@7b1b36d but they’re not enough at all to properly test all the cases (e.g. large-sized T).
nagisa
referenced this pull request
Mar 20, 2016
Closed
Implement placement-in protocol for relevant data structures #30172
This comment has been minimized.
This comment has been minimized.
|
Nice! I'd be curious to discuss our conventions a little more here as well. It seems like we may want to both implement the placer on the types directly as well as have methods, but then we've got naming issues etc, etc. Fun bikesheds! |
alexcrichton
added
the
T-libs
label
Mar 21, 2016
This comment has been minimized.
This comment has been minimized.
|
Yes, I think we should discuss the overall conventions here before going too much farther down that road -- let's be sure to cover it in the next libs meeting if we don't reach a resolution on this thread. |
This comment has been minimized.
This comment has been minimized.
|
I'm very much a fly on the wall with this change. I was wondering if there's a precedent for an operator pushing into a container elsewhere? It looks a bit strange to me. |
This comment has been minimized.
This comment has been minimized.
The collection library conventions were specifically audited before 1.0. How on earth |
This comment has been minimized.
This comment has been minimized.
|
Also, the PR name is a bit misleading, |
This comment has been minimized.
This comment has been minimized.
|
@aturon when discussing the feature please keep in mind the following point: This is unstable and implementation as it is currently is mostly done for everybody to try the feature and see what works and doesn’t. Notably the “Should &mut Vec implement Placer? Or should it provide a back_place method like LinkedList does instead?” should eventually answer itself through use – if people find
This is not an operator for pushing into containers; This is an operator for directly placing things into certain places that are not necessarily on the stack. Feature-wise the closest equivalent to this is C++’s emplacement, which, one could argue, hasn’t much special syntax. |
This comment has been minimized.
This comment has been minimized.
From the example for this PR:
Which is effectively the same as C++11 std::vector emplace_back() - maybe "push" isn't the right description? Placement or not, adding a new element to the end of the vector which sounds like a push operation to me. |
This comment has been minimized.
This comment has been minimized.
|
Is there any way we can avoid this becoming a de facto deprecation of the |
This comment has been minimized.
This comment has been minimized.
|
@bluss It's always better when it works, but there are some theoretical circumstances where it doesn't work, e.g.:
More generally placement won't work if creating the value to be placed requires borrowing something also borrowed by the place (unless of course if none of the borrows is However, I'm not sure whether this will be common enough to warrant keeping |
This comment has been minimized.
This comment has been minimized.
|
When emplacement roll-back is expensive and happens often,
Before flipping the coin vector shifts half of its elements to the right to prepare the scratch space for the new element in the position |
This comment has been minimized.
This comment has been minimized.
|
Thanks for the PR @apasel422! The libs team discussed this during triage yesterday, and the conclusion was that we probably want to hold off with more in-place implementations if we can. We're slightly uncomfortable that Specifically, especially as the discussion here indicates, we likely need to lay out some conventions for naming, usage, what implements @aturon has showed interest in helping shepherd a conventions RFC in this regard, as well. @apasel422 would you be interested in writing such an RFC? |
alexcrichton
closed this
Mar 24, 2016
This comment has been minimized.
This comment has been minimized.
|
@alexcrichton An RFC is totally reasonable for this (I'll start thinking about writing one in the next couple of days), but I am curious as to why #31696 was accepted. |
This comment has been minimized.
This comment has been minimized.
|
Yeah we concluded it was probably premature for us to accept #31696 unfortunately :( Thanks though! |
This comment has been minimized.
This comment has been minimized.
|
This is a very strange decision, emplacement needs implementation experience and performance measurements first of all, naming scheme is not important at the moment. |
This comment has been minimized.
This comment has been minimized.
|
@petrochenkov @nagisa You both make reasonable points about wanting to experiment quickly and not being too cautious here. But, on the other hand, we'd prefer not to rapidly get into a situation where we have suboptimal de facto conventions or inconsistency across (Personally, I think the names that landed for This doesn't need to be heavyweight -- the libs team would just like to see a brief writeup of some basic naming/impl scheme. We can move quickly on it. |
apasel422
deleted the
apasel422:placement
branch
Apr 18, 2016
apasel422
referenced this pull request
Aug 9, 2016
Open
`array.push(Foo { ... })` should construct `Foo` in-place #35531
This comment has been minimized.
This comment has been minimized.
|
@apasel422 the libs team discussed this recently and our conclusion was that we have some concrete ideas of how to revive this movement of implementations of these traits on collections. Would you still be interested in tackling this? |
This comment has been minimized.
This comment has been minimized.
|
Ah and to be more concrete (and to write down the notes), our conclusion was:
|
This comment has been minimized.
This comment has been minimized.
|
@alexcrichton Sure. I'll investigate resurrecting this later today. |
This comment has been minimized.
This comment has been minimized.
|
Awesome! We're also thinking that we could turn this into a tracking issue with all collections listed so we could keep up with the progress. Maybe you'd like to take a look first though and see where this would all need to be implemented? |
This comment has been minimized.
This comment has been minimized.
|
@alexcrichton I don't see how we can get syntax like let mut vec = vec![1, 2, 3];
vec <- 4;instead of let mut vec = vec![1, 2, 3];
&mut vec <- 4;as |
This comment has been minimized.
This comment has been minimized.
|
@apasel422 hm we were definitely not aware of that! We can perhaps push forward with |
This comment has been minimized.
This comment has been minimized.
|
@apasel422 we could make auto-ref work by temoprarily changing desugaring from Either way we have rust-lang/rfcs#1286. |
apasel422 commentedMar 20, 2016
Open questions:
BackPlacethe right name for the struct?&mut VecimplementPlacer? Or should it provide aback_placemethod likeLinkedListdoes instead?CC #30172, @rust-lang/libs, @pnkfelix