Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Placement protocol should allow failure in place creation. #1315

Closed
rphmeier opened this issue Oct 10, 2015 · 4 comments
Closed

Placement protocol should allow failure in place creation. #1315

rphmeier opened this issue Oct 10, 2015 · 4 comments
Labels
T-lang Relevant to the language team, which will review and decide on the RFC.

Comments

@rphmeier
Copy link

The only way to indicate failure in in-place allocation is to have your InPlace implementer return a Result from finalize(). However, most failures in in-place allocation will occur when there is insufficient space in the Placer to make a place. The implementation of Placer for ExchangeHeapSingleton in std sidesteps this issue by panicking when there isn't sufficient heap space, but that is hardly an acceptable solution for every implementation of in-place allocation.

Error handling for in-place allocation could become a little weird if every allocation can fail unexpectedly.

@pnkfelix
Copy link
Member

(We recently discussed this amongst the lang team.)

My standard response is: Why not in try!(alloc_place()) { value_expr } ?

(Or in the more recent proposed syntax, try!(alloc_place()) <- value_expr ?)

@huonw
Copy link
Member

huonw commented Oct 11, 2015

After we discussed on IRC (to late to bring up, unfortunately!), I realised this was encodable in the manner @pnkfelix said. See "Fallible Placement" for more details and a working example.

I'm inclined to close this issue, but maybe it could cover improving the support/smoothing out some of the strangeness.

@rphmeier
Copy link
Author

That's the solution I came up with for my Allocator trait, and it seems to work well enough. My only issue with it is one that you already raised in your Fallible Placement section: you have to do the allocation in the actual creation of the Placer, which makes the various trait implementations feel redundant.

@nrc nrc added the T-lang Relevant to the language team, which will review and decide on the RFC. label Aug 19, 2016
bors added a commit to rust-lang/rust that referenced this issue Apr 4, 2018
…sakis

Remove all unstable placement features

Closes #22181, #27779. Effectively makes the assortment of placement RFCs (rust-lang/rfcs#470, rust-lang/rfcs#809, rust-lang/rfcs#1228) 'unaccepted'. It leaves `box_syntax` and keeps the `<-` token as recognised by libsyntax.

------------------------

I don't know the correct process for unaccepting an unstable feature that was accepted as an RFC so...here's a PR.

Let me preface this by saying I'm not particularly happy about doing this (I know it'll be unpopular), but I think it's the most honest expression of how things stand today. I've been motivated by a [post on reddit](https://www.reddit.com/r/rust/comments/7wrqk2/when_will_box_and_placementin_syntax_be_stable/) which asks when these features will be stable - the features have received little RFC-style design work since the end of 2015 (~2 years ago) and leaving them in limbo confuses people who want to know where they're up to. Without additional design work that needs to happen (see the collection of unresolved questions later in this post) they can't really get stabilised, and I think that design work would be most suited to an RFC rather than (currently mostly unused) experimental features in Rust nightly.

I have my own motivations - it's very simple to 'defeat' placement in debug mode today and I don't want a placement in Rust that a) has no guarantees to work and b) has no plan for in-place serde deserialisation.

There's a quote in [1]: "Ordinarily these uncertainties might lead to the RFC being postponed. [The RFC seems like a promising direction hence we will accept since it] will thus give us immediate experience with the design and help in determining the best final solution.". I propose that there have been enough additional uncertainties raised since then that the original direction is less promising and we should be think about the problem anew.

(a historical note: the first mention of placement (under that name - uninit pointers were earlier) in an RFC AFAIK is [0] in late 2014 (pre-1.0). RFCs since then have built on this base - [1] is a comment in Feb 2015 accepting a more conservative design of the Place* traits - this is back when serde still required aster and seemed to break every other nightly! A lot has changed since then, perhaps placement should too)

------------------------

Concrete unresolved questions include:

 - making placement work in debug mode [7]
 - making placement work for serde/with fallible creation [5], [irlo2], [8]
 - trait design:
   - opting into not consuming the placer in `Placer::make_place` - [2]
   - trait proliferation - [4] (+ others in that thread)
   - fallible allocation - [3], [4] (+ others in that thread)
 - support for DSTs/unsized structs (if at all) - [1], [6]

More speculative unresolved questions include:

 - better trait design with in the context of future language features [irlo1] (Q11), [irlo3]
 - interaction between custom allocators and placement [irlo3]

[0] rust-lang/rfcs#470
[1] rust-lang/rfcs#809 (comment)
[2] rust-lang/rfcs#1286
[3] rust-lang/rfcs#1315
[4] #27779 (comment)
[5] #27779 (comment)
[6] #27779 (comment)
[7] #27779 (comment)
[8] rust-lang/rfcs#1228 (comment)
[irlo1] https://internals.rust-lang.org/t/placement-nwbi-faq-new-box-in-left-arrow/2789
[irlo2] https://internals.rust-lang.org/t/placement-nwbi-faq-new-box-in-left-arrow/2789/19
[irlo3] https://internals.rust-lang.org/t/lang-team-minutes-feature-status-report-placement-in-and-box/4646
@Centril
Copy link
Contributor

Centril commented Oct 14, 2018

This is moot now.

@Centril Centril closed this as completed Oct 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-lang Relevant to the language team, which will review and decide on the RFC.
Projects
None yet
Development

No branches or pull requests

5 participants