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

Add Pin::{into_inner,into_inner_unchecked} #60165

Merged
merged 1 commit into from
Apr 26, 2019

Conversation

Nemo157
Copy link
Member

@Nemo157 Nemo157 commented Apr 22, 2019

These functions are useful for unsafe code that needs to temporarily pull smart pointers out of the Pin, e.g. the change that inspired them is taking a Pin<Box<dyn Future>>, turning it into a *mut dyn Future via Box::into_raw(unsafe { Pin::into_inner_unchecked(pin) }) then later dropping this via drop(Pin::from(Box::from_raw(ptr))). This can be accomplished today via { let ptr = unsafe { Pin::get_unchecked_mut(pin.as_mut()) } as *mut dyn Future; mem::forget(pin); ptr }, but this is far more complicated and loses out on the symmetry of using Box::into_raw and Box::from_raw.

I'll extend the documentation on what guarantees into_inner_unchecked needs to uphold once I get some feedback on whether this API is wanted or not.

r? @withoutboats

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 22, 2019
@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-6.0 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
travis_time:end:0ff31038:start=1555933812837813930,finish=1555933898149287321,duration=85311473391
$ git checkout -qf FETCH_HEAD
travis_fold:end:git.checkout

Encrypted environment variables have been removed for security reasons.
See https://docs.travis-ci.com/user/pull-requests/#pull-requests-and-security-restrictions
$ export SCCACHE_BUCKET=rust-lang-ci-sccache2
$ export SCCACHE_REGION=us-west-1
$ export GCP_CACHE_BUCKET=rust-lang-ci-cache
$ export AWS_ACCESS_KEY_ID=AKIA46X5W6CZEJZ6XT55
---

[00:03:28] travis_fold:start:tidy
travis_time:start:tidy
tidy check
[00:03:28] tidy error: /checkout/src/libcore/pin.rs:467: TODO is deprecated; use FIXME
[00:03:30] some tidy checks failed
[00:03:30] 
[00:03:30] 
[00:03:30] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/tidy" "/checkout/src" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "--no-vendor" "--quiet"
[00:03:30] 
[00:03:30] 
[00:03:30] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test src/tools/tidy
[00:03:30] Build completed unsuccessfully in 0:00:45
[00:03:30] Build completed unsuccessfully in 0:00:45
[00:03:30] make: *** [tidy] Error 1
[00:03:30] Makefile:67: recipe for target 'tidy' failed
The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:02ff2c78
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
Mon Apr 22 11:55:17 UTC 2019
---
travis_time:end:064c3d02:start=1555934118297159773,finish=1555934118302074393,duration=4914620
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:2d21366c
$ ln -s . checkout && for CORE in obj/cores/core.*; do EXE=$(echo $CORE | sed 's|obj/cores/core\.[0-9]*\.!checkout!\(.*\)|\1|;y|!|/|'); if [ -f "$EXE" ]; then printf travis_fold":start:crashlog\n\033[31;1m%s\033[0m\n" "$CORE"; gdb --batch -q -c "$CORE" "$EXE" -iex 'set auto-load off' -iex 'dir src/' -iex 'set sysroot .' -ex bt -ex q; echo travis_fold":"end:crashlog; fi; done || true
travis_fold:end:after_failure.4
travis_fold:start:after_failure.5
travis_time:start:0ad175ae
travis_time:start:0ad175ae
$ cat ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers || true
cat: ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers: No such file or directory
travis_fold:end:after_failure.5
travis_fold:start:after_failure.6
travis_time:start:00029930
$ dmesg | grep -i kill

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

/// [`Unpin`]: ../../std/marker/trait.Unpin.html
#[unstable(feature = "pin_into_inner", issue = "0")]
#[inline(always)]
pub fn into_inner(pin: Pin<P>) -> P {
Copy link
Member

Choose a reason for hiding this comment

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

I'd expected we'd call this method unpin, though maybe that's too clever.

Copy link
Member Author

Choose a reason for hiding this comment

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

Either seems fine to me, let me know if I should change it.

@withoutboats
Copy link
Contributor

These seem like a good idea to add; no opinion about the name.

@Nemo157
Copy link
Member Author

Nemo157 commented Apr 24, 2019

Updated the docs to be similar detail to get{,_unchecked}_mut and added a tracking issue. Once the name question is resolved this is ready.

@cramertj
Copy link
Member

Maybe someone from @rust-lang/libs has an opinion on the name (into_inner vs. unpin)? If not, this works for me.

@alexcrichton
Copy link
Member

Since these are unstable I think it's ok to not block on a name and can probably land at any time.

I don't really have much experience personally with pin so a naive take on this is a preference of into_inner since it's an established convention. Again though that's a naive take and we can change our minds at any time while it's unstable!

@cramertj
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Apr 25, 2019

📌 Commit a0e0849 has been approved by cramertj

@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 Apr 25, 2019
@bors
Copy link
Contributor

bors commented Apr 25, 2019

⌛ Testing commit a0e0849 with merge 9027744c88135cf02ce637f129ec93aafa68e2ca...

@bors
Copy link
Contributor

bors commented Apr 25, 2019

💔 Test failed - checks-travis

@rust-highfive
Copy link
Collaborator

Your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
[00:04:24] sha256:d53c5e2d2845469b98e0a20fb01039c47f8791676fbac22778f4e4cafb2b5bce
[00:04:24] Attempting with retry: docker build --rm -t rust-ci -f /home/travis/build/rust-lang/rust/src/ci/docker/dist-x86_64-linux/Dockerfile /home/travis/build/rust-lang/rust/src/ci/docker
[00:04:24] Sending build context to Docker daemon  520.7kB
[00:04:24] Step 1/41 : FROM centos:5
[00:04:25] Get https://registry-1.docker.io/v2/library/centos/manifests/5: received unexpected HTTP status: 503 Service Unavailable
[00:04:26] Sending build context to Docker daemon  520.7kB
[00:04:26] Step 1/41 : FROM centos:5
[00:04:26] Step 1/41 : FROM centos:5
[00:04:26] Get https://registry-1.docker.io/v2/library/centos/manifests/5: received unexpected HTTP status: 503 Service Unavailable
[00:04:28] Sending build context to Docker daemon  520.7kB
[00:04:28] Step 1/41 : FROM centos:5
[00:04:28] Step 1/41 : FROM centos:5
[00:04:28] Get https://registry-1.docker.io/v2/library/centos/manifests/5: received unexpected HTTP status: 503 Service Unavailable
[00:04:32] Sending build context to Docker daemon  520.7kB
[00:04:32] Step 1/41 : FROM centos:5
[00:04:32] Step 1/41 : FROM centos:5
[00:04:32] Get https://registry-1.docker.io/v2/library/centos/manifests/5: received unexpected HTTP status: 503 Service Unavailable
[00:04:36] Sending build context to Docker daemon  520.7kB
[00:04:36] Step 1/41 : FROM centos:5
[00:04:36] Step 1/41 : FROM centos:5
[00:04:36] Get https://registry-1.docker.io/v2/library/centos/manifests/5: received unexpected HTTP status: 503 Service Unavailable
travis_time:end:116bbe00:start=1556212813284715939,finish=1556213090119882229,duration=276835166290
The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 1.
travis_time:start:09596a39
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
---
travis_time:end:00dc330e:start=1556213090932415737,finish=1556213090939344740,duration=6929003
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:0f2f29ee
$ ln -s . checkout && for CORE in obj/cores/core.*; do EXE=$(echo $CORE | sed 's|obj/cores/core\.[0-9]*\.!checkout!\(.*\)|\1|;y|!|/|'); if [ -f "$EXE" ]; then printf travis_fold":start:crashlog\n\033[31;1m%s\033[0m\n" "$CORE"; gdb --batch -q -c "$CORE" "$EXE" -iex 'set auto-load off' -iex 'dir src/' -iex 'set sysroot .' -ex bt -ex q; echo travis_fold":"end:crashlog; fi; done || true
travis_fold:end:after_failure.4
travis_fold:start:after_failure.5
travis_time:start:344028f0
travis_time:start:344028f0
$ cat ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers || true
cat: ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers: No such file or directory
travis_fold:end:after_failure.5
travis_fold:start:after_failure.6
travis_time:start:07c52d59
$ dmesg | grep -i kill

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Apr 25, 2019
@Nemo157
Copy link
Member Author

Nemo157 commented Apr 25, 2019

Looks like Docker Hub was having issues...

@cramertj
Copy link
Member

@bors retry

@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 Apr 25, 2019
Centril added a commit to Centril/rust that referenced this pull request Apr 25, 2019
Add Pin::{into_inner,into_inner_unchecked}

These functions are useful for unsafe code that needs to temporarily pull smart pointers out of the `Pin`, e.g. [the change that inspired them](Nemo157/futures-rs@b436178#diff-1a4e0ba4d1b539412ca576411ec6c7c2R258) is taking a `Pin<Box<dyn Future>>`, turning it into a `*mut dyn Future` via `Box::into_raw(unsafe { Pin::into_inner_unchecked(pin) })` then later dropping this via `drop(Pin::from(Box::from_raw(ptr)))`. This can be accomplished today via `{ let ptr = unsafe { Pin::get_unchecked_mut(pin.as_mut()) } as *mut dyn Future; mem::forget(pin); ptr }`, but this is far more complicated and loses out on the symmetry of using `Box::into_raw` and `Box::from_raw`.

I'll extend the documentation on what guarantees `into_inner_unchecked` needs to uphold once I get some feedback on whether this API is wanted or not.

r? @withoutboats
Centril added a commit to Centril/rust that referenced this pull request Apr 25, 2019
Add Pin::{into_inner,into_inner_unchecked}

These functions are useful for unsafe code that needs to temporarily pull smart pointers out of the `Pin`, e.g. [the change that inspired them](Nemo157/futures-rs@b436178#diff-1a4e0ba4d1b539412ca576411ec6c7c2R258) is taking a `Pin<Box<dyn Future>>`, turning it into a `*mut dyn Future` via `Box::into_raw(unsafe { Pin::into_inner_unchecked(pin) })` then later dropping this via `drop(Pin::from(Box::from_raw(ptr)))`. This can be accomplished today via `{ let ptr = unsafe { Pin::get_unchecked_mut(pin.as_mut()) } as *mut dyn Future; mem::forget(pin); ptr }`, but this is far more complicated and loses out on the symmetry of using `Box::into_raw` and `Box::from_raw`.

I'll extend the documentation on what guarantees `into_inner_unchecked` needs to uphold once I get some feedback on whether this API is wanted or not.

r? @withoutboats
Centril added a commit to Centril/rust that referenced this pull request Apr 26, 2019
Add Pin::{into_inner,into_inner_unchecked}

These functions are useful for unsafe code that needs to temporarily pull smart pointers out of the `Pin`, e.g. [the change that inspired them](Nemo157/futures-rs@b436178#diff-1a4e0ba4d1b539412ca576411ec6c7c2R258) is taking a `Pin<Box<dyn Future>>`, turning it into a `*mut dyn Future` via `Box::into_raw(unsafe { Pin::into_inner_unchecked(pin) })` then later dropping this via `drop(Pin::from(Box::from_raw(ptr)))`. This can be accomplished today via `{ let ptr = unsafe { Pin::get_unchecked_mut(pin.as_mut()) } as *mut dyn Future; mem::forget(pin); ptr }`, but this is far more complicated and loses out on the symmetry of using `Box::into_raw` and `Box::from_raw`.

I'll extend the documentation on what guarantees `into_inner_unchecked` needs to uphold once I get some feedback on whether this API is wanted or not.

r? @withoutboats
bors added a commit that referenced this pull request Apr 26, 2019
Rollup of 12 pull requests

Successful merges:

 - #59734 (Prevent failure in case no space left on device in rustdoc)
 - #59940 (Set cfg(test) when rustdoc is running with --test option)
 - #60134 (Fix index-page generation)
 - #60165 (Add Pin::{into_inner,into_inner_unchecked})
 - #60183 (Chalkify: Add builtin Copy/Clone)
 - #60225 (Introduce hir::ExprKind::Use and employ in for loop desugaring.)
 - #60247 (Implement Debug for Place using Place::iterate)
 - #60259 (Derive Default instead of new in applicable lint)
 - #60267 (Add feature-gate for f16c target feature)
 - #60284 (Do not allow const generics to depend on type parameters)
 - #60285 (Do not ICE when checking types against foreign fn)
 - #60289 (Make `-Z allow-features` work for stdlib features)

Failed merges:

r? @ghost
@bors bors merged commit a0e0849 into rust-lang:master Apr 26, 2019
@bors
Copy link
Contributor

bors commented Apr 26, 2019

⌛ Testing commit a0e0849 with merge 180edc2...

@bors
Copy link
Contributor

bors commented Apr 26, 2019

☔ The latest upstream changes (presumably #60296) made this pull request unmergeable. Please resolve the merge conflicts.

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Apr 26, 2019
@Nemo157 Nemo157 deleted the pin-into-inner branch August 27, 2019 10:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants