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

stabilize core parts of MaybeUninit #60445

Merged
merged 6 commits into from May 20, 2019

Conversation

@RalfJung
Copy link
Member

commented May 1, 2019

and deprecate mem::uninitialized in the future (1.40.0). This is part of implementing rust-lang/rfcs#1892.

Also expand the documentation a bit.

This type is currently primarily useful when dealing with partially initialized arrays. In libstd, it is used e.g. in BTreeMap (with some unstable APIs that however can all be replaced, less ergonomically, by stable ones). What we stabilize should also be enough for SmallVec (Cc @bluss).

Making this useful for structs requires rust-lang/rfcs#2582 or a commitment that references to uninitialized data are not insta-UB.

@rust-highfive

This comment has been minimized.

Copy link
Collaborator

commented May 1, 2019

r? @Kimundi

(rust_highfive has picked a reviewer for you, use r? to override)

@Centril

This comment has been minimized.

Copy link
Member

commented May 1, 2019

@rust-highfive rust-highfive assigned Centril and unassigned Kimundi May 1, 2019

@Centril Centril added this to the 1.36 milestone May 1, 2019

@rust-highfive

This comment was marked as resolved.

Copy link
Collaborator

commented May 1, 2019

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:08f27db8:start=1556733987099447641,finish=1556734074264998063,duration=87165550422
$ 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
---
[01:13:52] .................................................................................................... 1700/2958
[01:14:05] .................................................................................................... 1800/2958
[01:14:15] .................................................................................................... 1900/2958
[01:14:29] ........i.......................................................................i................... 2000/2958
[01:14:54] .........................................................................................F.......... 2100/2958
[01:15:17] ...............................................................................................test [run-pass] run-pass/mpsc_stress.rs has been running for over 60 seconds
[01:15:28] .................................................................................................... 2300/2958
[01:15:44] ..........................................ii........................................................ 2400/2958
[01:15:58] .................................................................................................... 2500/2958
[01:16:25] .................................................................................................... 2600/2958
---
[01:17:10] normalized stderr:
[01:17:10] warning: the feature `maybe_uninit` has been stable since 1.36.0 and no longer requires an attribute to enable
[01:17:10]   --> $DIR/panic-uninitialized-zeroed.rs:5:24
[01:17:10]    |
[01:17:10] LL | #![feature(never_type, maybe_uninit)]
[01:17:10]    |
[01:17:10]    = note: #[warn(stable_features)] on by default
[01:17:10] 
[01:17:10] 
[01:17:10] 
[01:17:10] 
[01:17:10] 
[01:17:10] The actual stderr differed from the expected stderr.
[01:17:10] Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/run-pass/panic-uninitialized-zeroed/panic-uninitialized-zeroed.stderr
[01:17:10] To update references, rerun the tests and pass the `--bless` flag
[01:17:10] To only update this specific test, also pass `--test-args panic-uninitialized-zeroed.rs`
[01:17:10] error: 1 errors occurred comparing output.
[01:17:10] status: exit code: 0
[01:17:10] status: exit code: 0
[01:17:10] command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/run-pass/panic-uninitialized-zeroed.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-Zui-testing" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-pass/panic-uninitialized-zeroed/a" "-Crpath" "-O" "-Zunstable-options" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-pass/panic-uninitialized-zeroed/auxiliary"
[01:17:10] ------------------------------------------
[01:17:10] 
[01:17:10] ------------------------------------------
[01:17:10] stderr:
[01:17:10] stderr:
[01:17:10] ------------------------------------------
[01:17:10] warning: the feature `maybe_uninit` has been stable since 1.36.0 and no longer requires an attribute to enable
[01:17:10]   --> /checkout/src/test/run-pass/panic-uninitialized-zeroed.rs:5:24
[01:17:10]    |
[01:17:10] LL | #![feature(never_type, maybe_uninit)]
[01:17:10]    |
[01:17:10]    = note: #[warn(stable_features)] on by default
[01:17:10] 
[01:17:10] 
---
[01:17:10] thread 'main' panicked at 'Some tests failed', src/tools/compiletest/src/main.rs:519:22
[01:17:10] note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
[01:17:10] 
[01:17:10] 
[01:17:10] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/compiletest" "--compile-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib" "--run-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib" "--rustc-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "--src-base" "/checkout/src/test/run-pass" "--build-base" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-pass" "--stage-id" "stage2-x86_64-unknown-linux-gnu" "--mode" "run-pass" "--target" "x86_64-unknown-linux-gnu" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "/usr/lib/llvm-6.0/bin/FileCheck" "--host-rustcflags" "-Crpath -O -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--target-rustcflags" "-Crpath -O -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--docck-python" "/usr/bin/python2.7" "--lldb-python" "/usr/bin/python2.7" "--gdb" "/usr/bin/gdb" "--quiet" "--llvm-version" "6.0.0\n" "--system-llvm" "--cc" "" "--cxx" "" "--cflags" "" "--llvm-components" "" "--llvm-cxxflags" "" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--color" "always"
[01:17:10] 
[01:17:10] 
[01:17:10] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
[01:17:10] Build completed unsuccessfully in 0:10:45
[01:17:10] Build completed unsuccessfully in 0:10:45
[01:17:10] make: *** [check] Error 1
[01:17:10] Makefile:48: recipe for target 'check' failed
The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:2e44e00e
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
Wed May  1 19:25:13 UTC 2019

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)

Show resolved Hide resolved src/libcore/mem.rs Outdated
Show resolved Hide resolved src/libcore/mem.rs Outdated
Show resolved Hide resolved src/libcore/mem.rs Outdated
Show resolved Hide resolved src/libcore/mem.rs Outdated
Show resolved Hide resolved src/libcore/mem.rs Outdated
Show resolved Hide resolved src/libcore/mem.rs
Show resolved Hide resolved src/libcore/mem.rs Outdated
Show resolved Hide resolved src/libcore/mem.rs Outdated

@RalfJung RalfJung force-pushed the RalfJung:maybe-uninit branch from 7344e98 to 478a3b0 May 1, 2019

#[inline]
#[rustc_deprecated(since = "2.0.0", reason = "use `mem::MaybeUninit::uninit` instead")]
#[rustc_deprecated(since = "1.40.0", reason = "use `mem::MaybeUninit` instead")]

This comment has been minimized.

Copy link
@cramertj

cramertj May 1, 2019

Member

Why not 1.36?

This comment has been minimized.

Copy link
@RalfJung

RalfJung May 1, 2019

Author Member

This function is widely used so I figured we'd give it some time.

This comment has been minimized.

Copy link
@Centril

Centril May 1, 2019

Member

I would suggest 1.38 instead as a middle ground. 1.34.0 seems rather long (~6 months from 1.36).

This comment has been minimized.

Copy link
@RalfJung

RalfJung May 2, 2019

Author Member

The precedent with #52994 is to keep it future-deprecated for 3 releases, that would be 1.39.

@Centril
Copy link
Member

left a comment

It's looks pretty great overall but here are some things that would be good to improve on.

I'll work up an FCP when I wake up tomorrow :)

Show resolved Hide resolved src/libcore/mem.rs Outdated
Show resolved Hide resolved src/libcore/mem.rs Outdated
Show resolved Hide resolved src/libcore/mem.rs Outdated
Show resolved Hide resolved src/libcore/mem.rs Outdated
Show resolved Hide resolved src/libcore/mem.rs Outdated
@Centril

This comment has been minimized.

Copy link
Member

commented May 2, 2019

Stabilization proposal

I propose that we stabilize the following API:

#[derive(Copy)]
pub union MaybeUninit<T> {
    uninit: (),
    value: ManuallyDrop<T>,
}

impl<T: Copy> Clone for MaybeUninit<T> { ... }

impl<T> MaybeUninit<T> {
    pub const fn new(val: T) -> MaybeUninit<T> { ... }

    pub const fn uninit() -> MaybeUninit<T> { ... }

    pub fn zeroed() -> MaybeUninit<T> { ... }

    pub fn as_ptr(&self) -> *const T { ... }

    pub fn as_mut_ptr(&mut self) -> *mut T { ... }

    pub unsafe fn assume_init(self) -> T { ... }
}

The proposed interface is minimal yet still useful as noted in the PR description:

This type is currently primarily useful when dealing with partially initialized arrays. In libstd, it is used e.g. in BTreeMap (with some unstable APIs that however can all be replaced, less ergonomically, by stable ones). What we stabilize should also be enough for SmallVec (Cc @bluss).

As the description notes, the API has also been tested inside the standard library and elsewhere.

The name of the type, MaybeUninit, has already gone through the FCP process and the other parts have been extensively bikeshedded. As such, I believe we are ready to commit to this today with more to come eventually.

The documentation for MaybeUninit<T> is already thorough, with more documentation being added in this PR.

A further note: rust-lang/rfcs#2582 has not been accepted yet and therefore we leave in place a warning in the documentation for anyone that tries to rely on those semantics with current surface syntax. Or as the PR description notes:

Making this useful for structs requires rust-lang/rfcs#2582 or a commitment that references to uninitialized data are not insta-UB.

As for the deprecation of mem::uninitialized, I propose that we schedule to deprecate uninitialized in 1.38. The function is widely used, but 3 months on stable should still be ample time to allow people to migrate.

With all that said:

@rfcbot merge

@rfcbot

This comment has been minimized.

Copy link

commented May 2, 2019

Team member @Centril has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

Show resolved Hide resolved src/libcore/mem.rs Outdated
@Centril
Copy link
Member

left a comment

Small nit; otherwise it looks great.

Show resolved Hide resolved src/libcore/mem.rs Outdated

@Centril Centril added the I-nominated label May 2, 2019

@withoutboats

This comment has been minimized.

Copy link
Contributor

commented May 2, 2019

Is there a crater run on how much of the ecosystem currently uses mem::uninitialized?

@Centril

This comment has been minimized.

Copy link
Member

commented May 2, 2019

@withoutboats I don't believe so.

@RalfJung RalfJung force-pushed the RalfJung:maybe-uninit branch from 99ac4b6 to 1916391 May 20, 2019

@RalfJung

This comment has been minimized.

Copy link
Member Author

commented May 20, 2019

@bors r=Centril

@bors

This comment has been minimized.

Copy link
Contributor

commented May 20, 2019

📌 Commit 1916391 has been approved by Centril

@RalfJung

This comment has been minimized.

Copy link
Member Author

commented May 20, 2019

@bors p=1

@bors

This comment has been minimized.

Copy link
Contributor

commented May 20, 2019

⌛️ Testing commit 1916391 with merge 6dabc5d...

bors added a commit that referenced this pull request May 20, 2019

Auto merge of #60445 - RalfJung:maybe-uninit, r=Centril
stabilize core parts of MaybeUninit

and deprecate mem::uninitialized in the future (1.40.0). This is part of implementing rust-lang/rfcs#1892.

Also expand the documentation a bit.

This type is currently primarily useful when dealing with partially initialized arrays. In libstd, it is used e.g. in `BTreeMap` (with some unstable APIs that however can all be replaced, less ergonomically, by stable ones). What we stabilize should also be enough for `SmallVec` (Cc @bluss).

Making this useful for structs requires rust-lang/rfcs#2582 or a commitment that references to uninitialized data are not insta-UB.
@pietroalbini

This comment has been minimized.

Copy link
Member

commented May 20, 2019

@bors retry

Yielding priority to the stable release.

@SimonSapin

This comment has been minimized.

Copy link
Contributor

commented May 20, 2019

@pietroalbini By the way, https://github.com/rust-lang/rust/blob/beta/src/bootstrap/channel.rs mentioning 1.35 suggests that 1.36 beta has not been cut yet, is that right? It’d be nice if this PR can make it in.

@RalfJung

This comment has been minimized.

Copy link
Member Author

commented May 20, 2019

The process says "Promote master to beta (T-2 days, Tuesday)", so I take it if we can land this today we are good?

That was the expectation anyways. ;)

@RalfJung

This comment has been minimized.

Copy link
Member Author

commented May 20, 2019

@bors p=50

@pietroalbini

This comment has been minimized.

Copy link
Member

commented May 20, 2019

@SimonSapin yep, beta will be cut tomorrow. I'll try to remember to check this PR before cutting it.

@bors

This comment has been minimized.

Copy link
Contributor

commented May 20, 2019

⌛️ Testing commit 1916391 with merge d35181a...

bors added a commit that referenced this pull request May 20, 2019

Auto merge of #60445 - RalfJung:maybe-uninit, r=Centril
stabilize core parts of MaybeUninit

and deprecate mem::uninitialized in the future (1.40.0). This is part of implementing rust-lang/rfcs#1892.

Also expand the documentation a bit.

This type is currently primarily useful when dealing with partially initialized arrays. In libstd, it is used e.g. in `BTreeMap` (with some unstable APIs that however can all be replaced, less ergonomically, by stable ones). What we stabilize should also be enough for `SmallVec` (Cc @bluss).

Making this useful for structs requires rust-lang/rfcs#2582 or a commitment that references to uninitialized data are not insta-UB.
@bors

This comment has been minimized.

Copy link
Contributor

commented May 20, 2019

☀️ Test successful - checks-travis, status-appveyor
Approved by: Centril
Pushing d35181a to master...

@bors bors added the merged-by-bors label May 20, 2019

@bors bors merged commit 1916391 into rust-lang:master May 20, 2019

2 checks passed

Travis CI - Pull Request Build Passed
Details
homu Test successful
Details

Centril added a commit to Centril/rust that referenced this pull request May 21, 2019

Rollup merge of rust-lang#61006 - RalfJung:maybe-uninit, r=Centril
adjust deprecation date of mem::uninitialized

In rust-lang#60445 we [decided](rust-lang#60445 (comment)) that we'd deprecate for 1.38 instead of 1.40, but I forgot to adjust for that.

Centril added a commit to Centril/rust that referenced this pull request May 21, 2019

Rollup merge of rust-lang#61006 - RalfJung:maybe-uninit, r=Centril
adjust deprecation date of mem::uninitialized

In rust-lang#60445 we [decided](rust-lang#60445 (comment)) that we'd deprecate for 1.38 instead of 1.40, but I forgot to adjust for that.

Centril added a commit to Centril/rust that referenced this pull request May 21, 2019

Rollup merge of rust-lang#61006 - RalfJung:maybe-uninit, r=Centril
adjust deprecation date of mem::uninitialized

In rust-lang#60445 we [decided](rust-lang#60445 (comment)) that we'd deprecate for 1.38 instead of 1.40, but I forgot to adjust for that.

Centril added a commit to Centril/rust that referenced this pull request May 22, 2019

Rollup merge of rust-lang#61006 - RalfJung:maybe-uninit, r=Centril
adjust deprecation date of mem::uninitialized

In rust-lang#60445 we [decided](rust-lang#60445 (comment)) that we'd deprecate for 1.38 instead of 1.40, but I forgot to adjust for that.

Centril added a commit to Centril/rust that referenced this pull request May 22, 2019

Rollup merge of rust-lang#61006 - RalfJung:maybe-uninit, r=Centril
adjust deprecation date of mem::uninitialized

In rust-lang#60445 we [decided](rust-lang#60445 (comment)) that we'd deprecate for 1.38 instead of 1.40, but I forgot to adjust for that.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.