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 Pin APIs (RFC 2349) #49150
Comments
withoutboats
added
B-RFC-approved
T-libs
C-tracking-issue
labels
Mar 18, 2018
withoutboats
referenced this issue
Mar 18, 2018
Merged
Standard library API for immovable types #2349
This comment has been minimized.
This comment has been minimized.
|
I now notice that stack pinning is not part of the RFC, @withoutboats are you planning on releasing a crate for this, or should I just copy the example code into my crate that needs it? |
This comment has been minimized.
This comment has been minimized.
|
@Nemo157 You should copy it and report your experience! The unresolved question about leaking One thing I'll note is that the stack pinning was not sufficient for things like |
This comment has been minimized.
This comment has been minimized.
|
My current usage is pretty trivial, a single-threaded executor running a single |
ExpHP
referenced this issue
Mar 23, 2018
Open
Tracking issue for `impl Trait` (RFC 1522, RFC 1951, RFC 2071) #34511
This comment has been minimized.
This comment has been minimized.
|
Just tried to experiment with the API. Looks like the following (suggested by RFC) definition of trait Future {
type Item;
type Error;
fn poll(self: Pin<Self>, cx: &mut task::Context) -> Poll<Self::Item, Self::Error>;
} |
This comment has been minimized.
This comment has been minimized.
|
Nevermind. Found a note about a plan to make |
This comment has been minimized.
This comment has been minimized.
Could you elaborate on that? |
This comment has been minimized.
This comment has been minimized.
|
@RalfJung You need |
This comment has been minimized.
This comment has been minimized.
|
@cramertj That sounds like a restriction of the |
This comment has been minimized.
This comment has been minimized.
|
@RalfJung Yes, that's correct. However, |
This comment has been minimized.
This comment has been minimized.
|
Given a |
This comment has been minimized.
This comment has been minimized.
|
@RalfJung No-- methods like |
This comment has been minimized.
This comment has been minimized.
|
It might be the case that we could get this to work with |
This comment has been minimized.
This comment has been minimized.
|
@cramertj I did not suggest to call |
This comment has been minimized.
This comment has been minimized.
|
@RalfJung Oh, I see. Yes, using a method to manually reborrow could work. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
I'll try and remember to post an example of some of the stuff I'm doing with |
This comment has been minimized.
This comment has been minimized.
|
Here's the full example of what I'm using for reading: pub trait Read {
type Error;
fn poll_read(
self: Pin<Self>,
cx: &mut task::Context,
buf: &mut [u8],
) -> Poll<usize, Self::Error>;
}
pub fn read_exact<'a, 'b: 'a, R: Read + 'a>(
mut this: Pin<'a, R>,
buf: &'b mut [u8],
) -> impl StableFuture<Item = (), Error = Error<R::Error>>
+ Captures<'a>
+ Captures<'b> {
async_block_pinned! {
let mut position = 0;
while position < buf.len() {
let amount = await!(poll_fn(|cx| {
Pin::borrow(&mut this).poll_read(cx, &mut buf[position..])
}))?;
position += amount;
if amount == 0 {
Err(Error::UnexpectedEof)?;
}
}
Ok(())
}
}This is slightly annoying as you have to pass instances through everywhere as #[async]
fn foo<'a, R>(source: Pin<'a, R>) -> Result<!, Error> where R: Read + 'a {
loop {
let mut buffer = [0; 8];
await!(read_exact(Pin::borrow(&mut source), &mut buffer[..]));
// do something with buffer
}
} |
This comment has been minimized.
This comment has been minimized.
|
I just had a thought that I could |
This comment has been minimized.
This comment has been minimized.
|
Concern: It seems likely that we want most types in libstd to implement Will this solve itself if we make sure to implement |
This comment has been minimized.
This comment has been minimized.
Yes, it seems like the same situation as |
This comment has been minimized.
This comment has been minimized.
|
A new question just occurred to me: When are |
This comment has been minimized.
This comment has been minimized.
|
@RalfJung |
This comment has been minimized.
This comment has been minimized.
|
Well, just like some types are |
This comment has been minimized.
This comment has been minimized.
|
@alercah I'm not super familiar with how packed types are implemented, but I believe its safe to pin to a packed type, just not to pin through a packed type. So the only case where you don't control the packed type is if you project to a public field of someone else's type, which could be just as unsafe because of |
This comment has been minimized.
This comment has been minimized.
A use case I could imagine is an intrusive linked list, where you only care about the address of the whole struct, but its got a bunch of badly aligned data you want to squash together without caring about the address of that data. |
bors
added a commit
that referenced
this issue
Sep 17, 2018
bors
added a commit
that referenced
this issue
Sep 18, 2018
bors
added a commit
that referenced
this issue
Sep 19, 2018
This comment has been minimized.
This comment has been minimized.
|
I've had to learn the Pin API due to my work with Futures, and I have a question.
Taken together, that allows for moving a pinned value with entirely safe code. Is this intended? What is the rationale for why this is safe to do? |
This comment has been minimized.
This comment has been minimized.
|
It looks like you have What you likely want is |
This comment has been minimized.
This comment has been minimized.
|
EDIT: no longer accurate
|
This comment has been minimized.
This comment has been minimized.
|
@tmandry Correct me if I'm wrong, but Note that |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Oh, the rules must have changed since I last used these. Sorry for the confusion. |
This comment has been minimized.
This comment has been minimized.
|
@tmandry Yes, the changes were very recent. Since things are still in flux, it's hard to keep up with all the changes. |
This comment has been minimized.
This comment has been minimized.
|
The comment by @tikue is correct. You need to remember that pins only pin one level of indirection down. |
This comment has been minimized.
This comment has been minimized.
|
@tikue @tmandry @withoutboats Thanks for the answers! It was very helpful. |
This comment has been minimized.
This comment has been minimized.
|
So what are the states of the two concerns now? ( |
This comment has been minimized.
This comment has been minimized.
|
@crlf0710 see the stabilization proposal. |
cramertj
referenced this issue
Nov 15, 2018
Merged
Expand std::pin module docs and rename std::pin::Pinned to PhantomPinned #55992
bors
added a commit
that referenced
this issue
Dec 12, 2018
This comment has been minimized.
This comment has been minimized.
|
@withoutboats Seems done? Shall we close? |
cramertj
closed this
Dec 27, 2018
rfcbot
removed
proposed-final-comment-period
disposition-merge
labels
Dec 27, 2018
This comment has been minimized.
This comment has been minimized.
|
Ok I apologise if this is not the place to post this, but I have been thinking about the
Here is a sketchy PoC of the idea: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=9aae40afe732babeafef9dab3d7525a8 Anyways, imho this should remain in |
This comment has been minimized.
This comment has been minimized.
|
@danielhenrymantilla I don't see how that solves the problem of compatibility with existing generic drop impls, like |
This comment has been minimized.
This comment has been minimized.
|
You're right it requires another thing: That should make it become
|
This comment has been minimized.
This comment has been minimized.
This has a huge effect on the overall API design, and was discussed extensively as part of the |
This comment has been minimized.
This comment has been minimized.
|
Yep, huge cost short term since all existing libraries would need to update to be But it is a fair concern (I did not know that it had been raised previously; thank you for pointing it out, @RalfJung ), and I guess that the short term practical drawbacks do out-weight the little safety gain of a |
withoutboats commentedMar 18, 2018
•
edited by scottmcm
Tracking issue for rust-lang/rfcs#2349
Blocking stabilization:
Unresolved questions:
!Unpindata?Edit: Summary comment: #49150 (comment) (in the hidden-by-default part)