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 upTracking issue for placement new #27779
Comments
alexcrichton
added
T-lang
T-libs
B-unstable
labels
Aug 13, 2015
This comment has been minimized.
This comment has been minimized.
|
At least this needs to be decided before this can become stable. |
huonw
changed the title
Tracking issue for library support of placement new
Tracking issue for placement new
Oct 8, 2015
huonw
added a commit
to huonw/rust
that referenced
this issue
Oct 8, 2015
huonw
added a commit
to huonw/rust
that referenced
this issue
Oct 8, 2015
This comment has been minimized.
This comment has been minimized.
|
I've adapted this issue from being explicitly focused on just the library aspects of placement new to encompassing both that and the compiler impl (since they're fairly intertwined). I've also been thinking about this a little recently. General links:
Trait proliferationWe currently have
|
huonw
added a commit
to huonw/rust
that referenced
this issue
Oct 8, 2015
This comment has been minimized.
This comment has been minimized.
briansmith
commented
Oct 9, 2015
|
How would this handle this use case? This is trying to create a way to store any instance of a trait
|
briansmith
referenced this issue
Oct 9, 2015
Closed
Document why *ring* does not use traits to model algorithm choice #21
This comment has been minimized.
This comment has been minimized.
|
I imagine you would want an array of |
huonw
referenced this issue
Oct 11, 2015
Closed
Placement protocol should allow failure in place creation. #1315
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
FYI draft of FAQ here https://internals.rust-lang.org/t/placemet-nwbi-faq-new-box-in-left-arrow/2789 |
This comment has been minimized.
This comment has been minimized.
I still think it's important to have placement insertion for basic collections ( |
This comment has been minimized.
This comment has been minimized.
|
@petrochenkov I don't think I have ever suggested stabilizing the protocol before it has been implemented for all the collection types that we can think of. :) (Feel free to point out where I may have misled...) |
This comment has been minimized.
This comment has been minimized.
|
@petrochenkov but I can see how the answer written there can be misinterpreted. I'll try to change that specific text; for the most part, I hope that discussion about the FAQ itself can be restricted to that internals thread. |
This comment has been minimized.
This comment has been minimized.
|
(I started writing the following as a comment on the FAQ thread on internals, before I saw it was partially addressed here, but I'll post it in full anyway...) So why does the placer protocol need two types/traits? As I understand it, a method like "emplace_back" would normally return basically a wrapper object with a reference to the container in question; Rust would then call One drawback would be that global allocators would have to look like Fallible allocators (i.e. allocators that can fail without panicking) cannot implement In lieu of that, such allocators would have to allocate before returning a Which is fine, but means that the ability to use constants as ...this is the point where I stopped writing, and now I see that the question of allowing Placers to fail has been touched on above, and one additional advantage of having a separate Placer is mentioned - that you can have short forms like (Sidenote - even if Rust's standard library doesn't care to deal with allocation failure, when it comes to the language itself, Rust's use of explicit option types rather than null pointers should make safety in the presence of allocation failure considerably easier than in C. Just saying.) |
This comment has been minimized.
This comment has been minimized.
|
@huonw, are the following traits not sufficient to reduce trait proliferation? trait Placer<Data: ?Sized> {
type Place: Place<Data>;
fn make_place(&mut self) -> Self::Place;
}
unsafe trait Place<Data: ?Sized> {
type Owner;
fn pointer(&mut self) -> *mut Data;
unsafe fn finalize(self) -> Self::Owner;
}
trait Boxer<Data: ?Sized>: Sized {
type Place: Place<Data, Owner=Self>;
fn make_place() -> Self::Place;
}
impl<T> Boxer<T> for Box<T> { /* ... */ }
impl<T> Place<T> for IntermediateBox<T> { /* ... */ } |
pcwalton
referenced this issue
Aug 8, 2016
Open
`array.push(Foo { ... })` should construct `Foo` in-place #35531
This comment has been minimized.
This comment has been minimized.
|
Wanted for WebRender. |
nrc
added
the
B-RFC-approved
label
Aug 29, 2016
This comment has been minimized.
This comment has been minimized.
|
Should the stabilization of |
hansihe
referenced this issue
Dec 29, 2016
Closed
Remove box indirection from resources (blocked by placement new) #40
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
A curious case has popped up where code like this causes a segfault: #![feature(box_syntax)]
use std::mem;
enum Void {}
struct RcBox<T> {
_a: usize,
_b: T,
}
pub unsafe fn bar() {
mem::forget(box RcBox {
_a: 1,
_b: mem::uninitialized::<Void>(),
});
}but avoiding the use of |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Though that's a good one to remember for the future. Huh. |
This comment has been minimized.
This comment has been minimized.
|
I suppose that the call to |
aidanhs
added a commit
to aidanhs/rust
that referenced
this issue
Mar 27, 2018
aidanhs
added a commit
to aidanhs/rust
that referenced
this issue
Mar 27, 2018
aidanhs
added a commit
to aidanhs/rust
that referenced
this issue
Mar 27, 2018
aidanhs
added a commit
to aidanhs/rust
that referenced
this issue
Mar 28, 2018
aidanhs
added a commit
to aidanhs/rust
that referenced
this issue
Mar 28, 2018
aidanhs
added a commit
to aidanhs/rust
that referenced
this issue
Mar 28, 2018
aidanhs
added a commit
to aidanhs/rust
that referenced
this issue
Mar 29, 2018
This comment has been minimized.
This comment has been minimized.
scottjmaddox
commented
Apr 2, 2018
|
Would it be possible to just avoid all the issues brought up with placement syntax and provide a |
SimonSapin
added a commit
to aidanhs/rust
that referenced
this issue
Apr 3, 2018
This comment has been minimized.
This comment has been minimized.
|
Placement new is imminently about to be/has been removed as an unstable feature and the RFCs unaccepted. The approved/merged PR is at #48333 and the tracking issues were at #22181 and #27779 (this issue). Note that this does not affect box syntax - there is a new tracking issue for that at #49733. Find the internals thread where you can discuss this more at https://internals.rust-lang.org/t/removal-of-all-unstable-placement-features/7223. Please add any thoughts there. This is the summary comment. So why remove placement?The implementation does not fulfil the design goalsAs described in rust-lang/rfcs#470 (referred to by the accepted rust-lang/rfcs#809), the implementation of placement new should
The summarised goals (from the same RFC text) are to be able to:
Now consider the description of C++ behaviour in https://isocpp.org/wiki/faq/dtors#placement-new and note that during construction, the Unfortunately, it is easy to show that rust does not construct objects directly into the allocation in debug mode. This is an artificially simple case that uses a struct literal rather than the very common Rust pattern of 'return value construction' (most It appears that the current implementation cannot competitive with C++ placement as-is. A new RFC might either propose different guarantees, or describe how the implementation should work given the very different method of construction in Rust (compared to C++). Straw man: "A call to a The functionality of placement is unpredictableAs described by the C++ goals for placement (mentioned above), placement is typically used because you need to have explicit control over the location an object is put at. We saw above that Rust fails in very simple cases, but even if it didn't there is a more general issue - there is no feedback to the user whether placement is actually working. For example, there is no way for a user to tell that Effectively, placement as implemented today is a 'slightly-better-effort to place values than normal assignment'. For an API that aims to offer additional control, this unpredictability is a significant problem. A new RFC might provide either provide clear guidance and documentation on what placement is guaranteed, or require that compilation will fail if a requested placement cannot succeed. Straw man 1: "Placement only works for arrays of bytes. Function calls (e.g. serde or anything with fallible creation) and DSTs will not work". Straw man 2: "If a same-name Specific unresolved questionsThere are a number of specific unresolved questions around the RFC(s), but there has been effectively no design work for about 2 years. These include (some already covered above):
More speculative unresolved questions include:
[0] rust-lang/rfcs#470 I've opted to list these rather than going into detail, as they're generally covered comprehensively by the corresponding links. A future RFC might examine these points to identify areas to explictly address, including (in no particular order):
|
aidanhs
referenced this issue
Apr 3, 2018
Closed
`box` and `in` expressions (tracking issue for RFC 809) #22181
This comment has been minimized.
This comment has been minimized.
|
@scottjmaddox I responded to you on the internals thread - https://internals.rust-lang.org/t/removal-of-all-unstable-placement-features/7223/2. |
bors
added a commit
that referenced
this issue
Apr 4, 2018
This comment has been minimized.
This comment has been minimized.
|
Closing since the unaccepting PR has been merged. |
aidanhs
closed this
Apr 4, 2018
This comment has been minimized.
This comment has been minimized.
|
@aidanhs this is the tracking RFC for |
This comment has been minimized.
This comment has been minimized.
|
@abonander good point. I've created a new tracking issue for just box syntax, updated my summary comment above and made a post on the thread in the internals forum. |
This comment has been minimized.
This comment has been minimized.
|
@aidanhs You'll need to update the tracking issue number in the Rust source as well. |
Robbepop
added a commit
to Robbepop/rust
that referenced
this issue
Apr 8, 2018
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Kixunil
commented
May 26, 2018
|
@aidanhs thank you for the summary! I've finally understood it well. |
alexcrichton commentedAug 13, 2015
This is a tracking issue for the unstable
placement_new_protocolfeature in the standard library, andplacement_in_syntax/box_syntaxin the compiler.(@pnkfelix adds below:)
Things to decide / finalize before stabilization:
in PLACE { BLOCK }vsPLACE <- EXPR. (See rust-lang/rfcs#1228 )&mut selfvsselffor thePlacer::make_place(rust-lang/rfcs#1286).box EXPRpart of this? (currently the desugaring doesn't work due to type inference issues).PlaceforInPlaceandBoxPlace, or just have theInPlacetrait independently from anyBoxPlace.