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

Unpin changes #50984

Merged
merged 4 commits into from
May 24, 2018
Merged

Unpin changes #50984

merged 4 commits into from
May 24, 2018

Conversation

cramertj
Copy link
Member

@cramertj cramertj commented May 23, 2018

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 23, 2018
@aturon
Copy link
Member

aturon commented May 23, 2018

lgtm

@aturon
Copy link
Member

aturon commented May 23, 2018

@bors: r+

(There should be plenty of time for further comments before this actually gets to the front of the queue...)

@bors
Copy link
Contributor

bors commented May 23, 2018

📌 Commit 15d2f96 has been approved by aturon

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 23, 2018
@withoutboats
Copy link
Contributor

👍

@@ -269,6 +270,15 @@ impl<T> Option<T> {
}
}

/// Converts from `Option<T>` to `Option<PinMut<'_, T>>`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should say "from PinMut<'_, Option<T> to".

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is the case, we should better change the docs of as_ref() and as_mut() as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I think that would make sense, though.

@RalfJung
Copy link
Member

Add Option::as_pin_mut

This fixes the pinned invariant for Option to be structural, i.e., a pinned option has its content pinned. I feel this should be written down explicitly somewhere, maybe next to the enum Option? One consequence of this is that adding impl<T> Unpin for Option<T> would lead to unsoundness.

@cramertj
Copy link
Member Author

cramertj commented May 23, 2018

@RalfJung Yes, this does fix that invariant-- i'm also interested in doing the same for other structures in std, such as AssertUnwindSafe, Result, and Box. There's not a good way to explicitly opt-out of Unpin in the case where you want this structure-- I think we might want a language feature for this. Perhaps it's not necessary, as the crate that performs pinning projections is the one that would have to add the impl? It seems unlikely that an impl for Option would fall through the cracks, but I could see impls like this sneaking into community libraries.

@pythonesque
Copy link
Contributor

pythonesque commented May 23, 2018

@cramertj One thing @RalfJung and I discussed was that there should still be a way to unsafely implement Unpin that would not conflict with the existence of pin projections--this would preserve our existing ability to conditionally implement Unpin with pin projections.

I don't think I have any concerns about this change otherwise, conceptually. However, I am a little wary about this implementation (just marking it safe) because unlike Drop, Unpin can (currently) be implemented with bounds that don't always exist on the type itself, so I'm not sure how easy it will be to integrate detecting it into the existing procedural macro. Obviously that would not be an issue for a compiler-enforced solution, but that hasn't actually been created yet.

@RalfJung
Copy link
Member

i'm also interested in doing the same for other structures in std, such as AssertUnwindSafe, Result, and Box

Why Box? I expected Box to be unconditionally Unpin, like other smart pointers. Result should be fine though and other non-pointer-wrappers.

@cramertj
Copy link
Member Author

cramertj commented May 23, 2018

@RalfJung Why would Box and other smart pointers be unconditionally Unpin? Does it not seem useful to project in those cases? I had thought that Arc would even be unconditionally unpin and give access to Pin of the innards, although perhaps we'd want to make that into a wrapper type so that we could add ArcBox someday (which would allow you to move out of an Arc if the refcount was one).

@RalfJung
Copy link
Member

I would usually expect that when something is pinned, that is a statement about the memory this thing is allocated in -- which doesn't propagate through pointers. Also see the discussion at #49621.

@cramertj
Copy link
Member Author

@RalfJung Yes, that intuition makes sense. I had a different intuition, though-- I was thinking of Box as a sort of single-field wrapper type like AssertUnwindSafe that just happened to store its inner field in a separate allocation. Neither interpretation is more clearly correct to me than the other, and I don't see strong utility in being able to project into a box (just use PInBox if you don't need to move out) nor making Box unconditionally Unpin (what does being able to move out of a PinMut<Box<NotUnpinType>> get you?).

I lean slightly towards my original intuition (single-field wrapper with out-of-line storage) because it allows more broad trait impls and makes more code that expects to be able to project PinMut correct.

@bors
Copy link
Contributor

bors commented May 24, 2018

⌛ Testing commit 15d2f96 with merge c2d4603...

bors added a commit that referenced this pull request May 24, 2018
@bors
Copy link
Contributor

bors commented May 24, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: aturon
Pushing c2d4603 to master...

@bors bors merged commit 15d2f96 into rust-lang:master May 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants