-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
re-land #62150 (Implement mem::{zeroed,uninitialized} in terms of MaybeUninit) #62825
Comments
Note that (to my knowledge) this change is in nightly only currently, and won't become stable until 1.38 (released in late September). But it causes trouble already now e.g. by making CI fail, I suppose. Nominating for lang team discussion. I hope I am doing this right.^^ |
Some more relevant discussion:
|
Rather than panicking at runtime, could we detect this at compile-time, and issue a compile-time warning about calling I think we need some kind of compile-time warning that people can start fixing, so that people know they need to fix this. Otherwise, we'll be in the same boat when we un-revert this. |
Based on discussion in the lang team: we'd be fine with backing this out, but we do need a lint or similar mechanism to make sure people notice and fix code. |
I assume you are responding to this proposal? For some cases yes, but not reliably in generic contexts. |
On July 25, 2019 12:38:13 PM PDT, Ralf Jung ***@***.***> wrote:
@joshtriplett
> Rather than panicking at runtime, could we detect this at
compile-time, and issue a compile-time warning about calling
mem::uninitialized or mem::zeroed with a type of &T or a function type
or similar?
I assume you are responding to [this
proposal](https://internals.rust-lang.org/t/make-mem-uninitialized-and-mem-zeroed-panic-for-some-types-where-0-is-a-niche/10605)?
For some cases yes, but not reliably in generic contexts.
Doesn't have to be perfect. If we can detect common cases like `&T` and function types, that would help people know they need to migrate.
|
Agreed. I think we can do something that traverses the type as far as we see it, and complains when it finds a reference, We should probably stop looking when encountering an enum, or else we'd have to figure out which variant would be picked by the all-0 bit pattern and then look at the fields of that. |
@ishitatsuyuki beta branches in 12 days. If you want this to be backed out, someone has to do it before that. |
Is the lint a requirement for backing out? If so, we may want to reach a consensus on how to implement the check. |
No, I don't think so. @joshtriplett could you clarify? |
Definitely not a requirement for backing out. More a requirement to happen well in advance of re-adding. |
I'm working on a lint, should have a PR ready tomorrow. |
Lint PR up at #63346 |
@joshtriplett what is the timeline you had in mind for putting the change back in place? To my knowledge, the only crates that we know got broken by this are x11-rs (the broken part of which is "one giant hack" in the words of the maintainer) and old versions of |
Lint on some incorrect uses of mem::zeroed / mem::uninitialized Cc rust-lang#62825 and https://internals.rust-lang.org/t/make-mem-uninitialized-and-mem-zeroed-panic-for-some-types-where-0-is-a-niche/10605 This does not yet handle `NonNull`/`NonZero*`, but it is a start. I also improved some doc issues I hit on the way, and added a useful helper to `TyS`.
Lint on some incorrect uses of mem::zeroed / mem::uninitialized Cc rust-lang#62825 and https://internals.rust-lang.org/t/make-mem-uninitialized-and-mem-zeroed-panic-for-some-types-where-0-is-a-niche/10605 This does not yet handle `NonNull`/`NonZero*`, but it is a start. I also improved some doc issues I hit on the way, and added a useful helper to `TyS`. EDIT: I added the relnotes label mostly as a proposal -- I think this is worth mentioning, but leave the decision up to the release team.
Lint on some incorrect uses of mem::zeroed / mem::uninitialized Cc rust-lang#62825 and https://internals.rust-lang.org/t/make-mem-uninitialized-and-mem-zeroed-panic-for-some-types-where-0-is-a-niche/10605 This does not yet handle `NonNull`/`NonZero*`, but it is a start. I also improved some doc issues I hit on the way, and added a useful helper to `TyS`. EDIT: I added the relnotes label mostly as a proposal -- I think this is worth mentioning, but leave the decision up to the release team.
We discussed a one version grace period in this issue (see OP) and in the language team meeting. The lint has also been implemented (and then some...) so I think we should go ahead and revert the revert. |
Okay. I personally would prefer to have a dynamic check in place as well on top of the static check that we have, just to be sure. But either way I won't have time to work on this for this release cycle. |
Status update: I filed #66059 to add some run-time protection on top of the static lint that we already have (a first version of that lint is stable for 5 weeks already; a stronger version will become stable in a week). Once the run-time protection lands, my plan is to wait a week to see if there's a big outcry like there was when #62150 landed. If not, I'll submit a PR to re-implement #62150 and kill the |
mem::zeroed/uninit: panic on types that do not permit zero-initialization r? @eddyb @oli-obk Cc rust-lang#62825 Also see [this summary comment](rust-lang#66059 (comment))
mem::zeroed/uninit: panic on types that do not permit zero-initialization r? @eddyb @oli-obk Cc rust-lang#62825 Also see [this summary comment](rust-lang#66059 (comment))
Re-landing PR is up at #69922. |
implement zeroed and uninitialized with MaybeUninit This is the second attempt of doing such a change (first PR: rust-lang#62150). The last change [got reverted](rust-lang#63343) because it [caused](rust-lang#62825) some [issues](rust-lang#52898 (comment)) in [code that incorrectly used these functions](AltF02/x11-rs#99). Since then, the [problematic code has been fixed](AltF02/x11-rs#101), and rustc [gained a lint](rust-lang#63346) that is able to detect many misuses of these functions statically and a [dynamic check that panics](rust-lang#66059) instead of causing UB for some incorrect uses. Fixes rust-lang#62825
implement zeroed and uninitialized with MaybeUninit This is the second attempt of doing such a change (first PR: rust-lang#62150). The last change [got reverted](rust-lang#63343) because it [caused](rust-lang#62825) some [issues](rust-lang#52898 (comment)) in [code that incorrectly used these functions](AltF02/x11-rs#99). Since then, the [problematic code has been fixed](AltF02/x11-rs#101), and rustc [gained a lint](rust-lang#63346) that is able to detect many misuses of these functions statically and a [dynamic check that panics](rust-lang#66059) instead of causing UB for some incorrect uses. Fixes rust-lang#62825
#62150 got reverted to give users some time to migrate; we should re-land it.
Original issue:
#62150 has changed the behavior of
mem::uninitialized()
(andzeroed()
), causing a few popular crates to be killed bySIGILL
. A writeup can be found here.There are cases where outdated (EOL) versions of downstream dependencies have this issue. In that case, the upstream crate will have to migrate to a newer major version of the dependency, which means it will have to deal with those breaking changes.
Therefore, I suggest we back out the change for at least one stable release, providing the community with the time to upgrade.
cc @RalfJung
The text was updated successfully, but these errors were encountered: