Stabilize const_maybe_uninit_zeroed
and const_mem_zeroed
by tgross35 · Pull Request #116218 · rust-lang/rust (original) (raw)
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 andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Conversation51 Commits2 Checks0 Files changed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
[ Show hidden characters]({{ revealButtonHref }})
rustbot added S-waiting-on-review
Status: Awaiting review from the assignee but also interested parties.
Relevant to the library team, which will review and decide on the PR/issue.
Area: Constant evaluation, covers all const contexts (static, const fn, ...)
Relevant to the library API team, which will review and decide on the PR/issue.
labels
Relevant to the library team, which will review and decide on the PR/issue.
label
Relevant to the language team, which will review and decide on the PR/issue.
label
LGTM, but the FCP should probably include t-lang since this makes the internal mutable referece/ptr support in our const-eval engine accessible from stable for the first time. I'm not at all concerned about doing so (that support is very mature), but it's worth a bit of extra scrutiny.
This change is insta-stable, so needs a completed FCP to proceed.
label
Team member @dtolnay 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!
cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns.
See this document for info about what commands tagged team members can give me.
Should we make https://doc.rust-lang.org/std/mem/fn.zeroed.html const
at the same time, since it's a simple wrapper?
But either way, no concerns from me about doing this. Letting people have a zeroinitializer
easily makes sense.
@rfcbot reviewed
(And we could easily add an intrinsic to get a zeroed value if for some reason we had to stop using &mut
in the implementation of this for a while.)
/// |
---|
/// static PLUGIN_LIST: [PluginInfo; 2] = [ |
/// PluginInfo { id: 1, action: Some(|x |
/// unsafe { MaybeUninit::zeroed().assume_init() } |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: could we find a better example? This could be PluginInfo { id: 0, action: None }
, which is both shorter and doesn't need unsafe
.
(And please put a // SAFETY: …
comment on any unsafe { … }
used in examples, to encourage good behaviour and explain why it's not UB.)
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, any suggestions? I was struggling to come up with something better, null-terminated arrays for plugins are just the use case I always come across
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The entire problem with a good example here is that you use zeroed when the full thing would be a pain to write or even look at. So usually that means that you're talking about some type with 50 integer fields or something. But regardless of details it's "something so big it doesn't fit in a 2 line example".
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we able to use dev dependencies? Is there a libc
use case to feature here?
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that a generic function can be a good example.
#![feature(const_maybe_uninit_zeroed)]
use core::mem::MaybeUninit;
struct Time32(u32); struct Time64(u64); struct Time(T);
// I couldn't come up with a good name. Zeroable? trait SafeZeroed {}
impl SafeZeroed for Time32 {} impl SafeZeroed for Time64 {} impl<T: SafeZeroed> SafeZeroed for Time {}
const fn time_zeroed() -> Time where Time: SafeZeroed, { unsafe { MaybeUninit::zeroed().assume_init() } }
(Well, in this example it makes more sense to define a trait that has TimeTrait::zeroed
, etc...)
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SafeZeroed would actually have to be an unsafe trait in this scenario.
Honestly I don't think we need example code on this particular function/method. It makes the all-zeroed value, that's already extremely simple I think.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really just wanted a sanity check test for the functionality, but agree it’s redundant as an example. And that usually it’s with pretty big C structs for plugins, so there isn’t really a good minimal example. I’ll remove the example and change it to a unit test.
(Not in front of a computer now but I will do it tomorrow)
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nevermind, I was able to do it now
@dtolnaybot
ready 🙂
tgross35 changed the title
Stabilize Stabilize const_maybe_uninit_zeroed
const_maybe_uninit_zeroed
and const_mem_zeroed
I updated this PR to do mem::zeroed
as well. It depends on intrinsic assert_zero_valid
becoming const, I assumed that isn't a problem either.
Yeah, assert_inhabited, assert_zero_valid, assert_mem_uninitialized_valid are very similar and can just all be made stably const (since assert_inhabited already is stably const).
Even easier 🙂 I added assert_mem_uninitialized_valid
This comment has been minimized.
kuba-moo pushed a commit to linux-netdev/testing that referenced this pull request
This patch adds abstractions to implement network PHY drivers; the driver registration and bindings for some of callback functions in struct phy_driver and many genphy_ functions.
This feature is enabled with CONFIG_RUST_PHYLIB_ABSTRACTIONS=y.
This patch enables unstable const_maybe_uninit_zeroed feature for kernel crate to enable unsafe code to handle a constant value with uninitialized data. With the feature, the abstractions can initialize a phy_driver structure with zero easily; instead of initializing all the members by hand. It's supposed to be stable in the not so distant future.
Link: rust-lang/rust#116218
Signed-off-by: FUJITA Tomonori fujita.tomonori@gmail.com Reviewed-by: Andrew Lunn andrew@lunn.ch Signed-off-by: NipaLocal <nipa@local>
kuba-moo pushed a commit to linux-netdev/testing that referenced this pull request
This patch adds abstractions to implement network PHY drivers; the driver registration and bindings for some of callback functions in struct phy_driver and many genphy_ functions.
This feature is enabled with CONFIG_RUST_PHYLIB_ABSTRACTIONS=y.
This patch enables unstable const_maybe_uninit_zeroed feature for kernel crate to enable unsafe code to handle a constant value with uninitialized data. With the feature, the abstractions can initialize a phy_driver structure with zero easily; instead of initializing all the members by hand. It's supposed to be stable in the not so distant future.
Link: rust-lang/rust#116218
Signed-off-by: FUJITA Tomonori fujita.tomonori@gmail.com Reviewed-by: Andrew Lunn andrew@lunn.ch Signed-off-by: NipaLocal <nipa@local>
kuba-moo pushed a commit to linux-netdev/testing that referenced this pull request
This patch adds abstractions to implement network PHY drivers; the driver registration and bindings for some of callback functions in struct phy_driver and many genphy_ functions.
This feature is enabled with CONFIG_RUST_PHYLIB_ABSTRACTIONS=y.
This patch enables unstable const_maybe_uninit_zeroed feature for kernel crate to enable unsafe code to handle a constant value with uninitialized data. With the feature, the abstractions can initialize a phy_driver structure with zero easily; instead of initializing all the members by hand. It's supposed to be stable in the not so distant future.
Link: rust-lang/rust#116218
Signed-off-by: FUJITA Tomonori fujita.tomonori@gmail.com Reviewed-by: Andrew Lunn andrew@lunn.ch Signed-off-by: NipaLocal <nipa@local>
kuba-moo pushed a commit to linux-netdev/testing that referenced this pull request
This patch adds abstractions to implement network PHY drivers; the driver registration and bindings for some of callback functions in struct phy_driver and many genphy_ functions.
This feature is enabled with CONFIG_RUST_PHYLIB_ABSTRACTIONS=y.
This patch enables unstable const_maybe_uninit_zeroed feature for kernel crate to enable unsafe code to handle a constant value with uninitialized data. With the feature, the abstractions can initialize a phy_driver structure with zero easily; instead of initializing all the members by hand. It's supposed to be stable in the not so distant future.
Link: rust-lang/rust#116218
Signed-off-by: FUJITA Tomonori fujita.tomonori@gmail.com Reviewed-by: Andrew Lunn andrew@lunn.ch Signed-off-by: NipaLocal <nipa@local>
kuba-moo pushed a commit to linux-netdev/testing that referenced this pull request
This patch adds abstractions to implement network PHY drivers; the driver registration and bindings for some of callback functions in struct phy_driver and many genphy_ functions.
This feature is enabled with CONFIG_RUST_PHYLIB_ABSTRACTIONS=y.
This patch enables unstable const_maybe_uninit_zeroed feature for kernel crate to enable unsafe code to handle a constant value with uninitialized data. With the feature, the abstractions can initialize a phy_driver structure with zero easily; instead of initializing all the members by hand. It's supposed to be stable in the not so distant future.
Link: rust-lang/rust#116218
Signed-off-by: FUJITA Tomonori fujita.tomonori@gmail.com Reviewed-by: Andrew Lunn andrew@lunn.ch Signed-off-by: NipaLocal <nipa@local>
kuba-moo pushed a commit to linux-netdev/testing that referenced this pull request
This patch adds abstractions to implement network PHY drivers; the driver registration and bindings for some of callback functions in struct phy_driver and many genphy_ functions.
This feature is enabled with CONFIG_RUST_PHYLIB_ABSTRACTIONS=y.
This patch enables unstable const_maybe_uninit_zeroed feature for kernel crate to enable unsafe code to handle a constant value with uninitialized data. With the feature, the abstractions can initialize a phy_driver structure with zero easily; instead of initializing all the members by hand. It's supposed to be stable in the not so distant future.
Link: rust-lang/rust#116218
Signed-off-by: FUJITA Tomonori fujita.tomonori@gmail.com Reviewed-by: Andrew Lunn andrew@lunn.ch Reviewed-by: Alice Ryhl aliceryhl@google.com Signed-off-by: NipaLocal <nipa@local>
kuba-moo pushed a commit to linux-netdev/testing that referenced this pull request
This patch adds abstractions to implement network PHY drivers; the driver registration and bindings for some of callback functions in struct phy_driver and many genphy_ functions.
This feature is enabled with CONFIG_RUST_PHYLIB_ABSTRACTIONS=y.
This patch enables unstable const_maybe_uninit_zeroed feature for kernel crate to enable unsafe code to handle a constant value with uninitialized data. With the feature, the abstractions can initialize a phy_driver structure with zero easily; instead of initializing all the members by hand. It's supposed to be stable in the not so distant future.
Link: rust-lang/rust#116218
Signed-off-by: FUJITA Tomonori fujita.tomonori@gmail.com Reviewed-by: Andrew Lunn andrew@lunn.ch Reviewed-by: Alice Ryhl aliceryhl@google.com Signed-off-by: NipaLocal <nipa@local>
kuba-moo pushed a commit to linux-netdev/testing that referenced this pull request
This patch adds abstractions to implement network PHY drivers; the driver registration and bindings for some of callback functions in struct phy_driver and many genphy_ functions.
This feature is enabled with CONFIG_RUST_PHYLIB_ABSTRACTIONS=y.
This patch enables unstable const_maybe_uninit_zeroed feature for kernel crate to enable unsafe code to handle a constant value with uninitialized data. With the feature, the abstractions can initialize a phy_driver structure with zero easily; instead of initializing all the members by hand. It's supposed to be stable in the not so distant future.
Link: rust-lang/rust#116218
Signed-off-by: FUJITA Tomonori fujita.tomonori@gmail.com Reviewed-by: Andrew Lunn andrew@lunn.ch Reviewed-by: Alice Ryhl aliceryhl@google.com Signed-off-by: NipaLocal <nipa@local>
kuba-moo pushed a commit to linux-netdev/testing that referenced this pull request
This patch adds abstractions to implement network PHY drivers; the driver registration and bindings for some of callback functions in struct phy_driver and many genphy_ functions.
This feature is enabled with CONFIG_RUST_PHYLIB_ABSTRACTIONS=y.
This patch enables unstable const_maybe_uninit_zeroed feature for kernel crate to enable unsafe code to handle a constant value with uninitialized data. With the feature, the abstractions can initialize a phy_driver structure with zero easily; instead of initializing all the members by hand. It's supposed to be stable in the not so distant future.
Link: rust-lang/rust#116218
Signed-off-by: FUJITA Tomonori fujita.tomonori@gmail.com Reviewed-by: Andrew Lunn andrew@lunn.ch Reviewed-by: Alice Ryhl aliceryhl@google.com Signed-off-by: NipaLocal <nipa@local>
kuba-moo pushed a commit to linux-netdev/testing that referenced this pull request
This patch adds abstractions to implement network PHY drivers; the driver registration and bindings for some of callback functions in struct phy_driver and many genphy_ functions.
This feature is enabled with CONFIG_RUST_PHYLIB_ABSTRACTIONS=y.
This patch enables unstable const_maybe_uninit_zeroed feature for kernel crate to enable unsafe code to handle a constant value with uninitialized data. With the feature, the abstractions can initialize a phy_driver structure with zero easily; instead of initializing all the members by hand. It's supposed to be stable in the not so distant future.
Link: rust-lang/rust#116218
Signed-off-by: FUJITA Tomonori fujita.tomonori@gmail.com Reviewed-by: Andrew Lunn andrew@lunn.ch Reviewed-by: Alice Ryhl aliceryhl@google.com Signed-off-by: NipaLocal <nipa@local>
kuba-moo pushed a commit to linux-netdev/testing that referenced this pull request
This patch adds abstractions to implement network PHY drivers; the driver registration and bindings for some of callback functions in struct phy_driver and many genphy_ functions.
This feature is enabled with CONFIG_RUST_PHYLIB_ABSTRACTIONS=y.
This patch enables unstable const_maybe_uninit_zeroed feature for kernel crate to enable unsafe code to handle a constant value with uninitialized data. With the feature, the abstractions can initialize a phy_driver structure with zero easily; instead of initializing all the members by hand. It's supposed to be stable in the not so distant future.
Link: rust-lang/rust#116218
Signed-off-by: FUJITA Tomonori fujita.tomonori@gmail.com Reviewed-by: Andrew Lunn andrew@lunn.ch Reviewed-by: Alice Ryhl aliceryhl@google.com Signed-off-by: NipaLocal <nipa@local>
kuba-moo pushed a commit to linux-netdev/testing that referenced this pull request
This patch adds abstractions to implement network PHY drivers; the driver registration and bindings for some of callback functions in struct phy_driver and many genphy_ functions.
This feature is enabled with CONFIG_RUST_PHYLIB_ABSTRACTIONS=y.
This patch enables unstable const_maybe_uninit_zeroed feature for kernel crate to enable unsafe code to handle a constant value with uninitialized data. With the feature, the abstractions can initialize a phy_driver structure with zero easily; instead of initializing all the members by hand. It's supposed to be stable in the not so distant future.
Link: rust-lang/rust#116218
Signed-off-by: FUJITA Tomonori fujita.tomonori@gmail.com Reviewed-by: Andrew Lunn andrew@lunn.ch Reviewed-by: Alice Ryhl aliceryhl@google.com Signed-off-by: NipaLocal <nipa@local>
kuba-moo pushed a commit to linux-netdev/testing that referenced this pull request
This patch adds abstractions to implement network PHY drivers; the driver registration and bindings for some of callback functions in struct phy_driver and many genphy_ functions.
This feature is enabled with CONFIG_RUST_PHYLIB_ABSTRACTIONS=y.
This patch enables unstable const_maybe_uninit_zeroed feature for kernel crate to enable unsafe code to handle a constant value with uninitialized data. With the feature, the abstractions can initialize a phy_driver structure with zero easily; instead of initializing all the members by hand. It's supposed to be stable in the not so distant future.
Link: rust-lang/rust#116218
Signed-off-by: FUJITA Tomonori fujita.tomonori@gmail.com Reviewed-by: Andrew Lunn andrew@lunn.ch Reviewed-by: Alice Ryhl aliceryhl@google.com Signed-off-by: NipaLocal <nipa@local>
kuba-moo pushed a commit to linux-netdev/testing that referenced this pull request
This patch adds abstractions to implement network PHY drivers; the driver registration and bindings for some of callback functions in struct phy_driver and many genphy_ functions.
This feature is enabled with CONFIG_RUST_PHYLIB_ABSTRACTIONS=y.
This patch enables unstable const_maybe_uninit_zeroed feature for kernel crate to enable unsafe code to handle a constant value with uninitialized data. With the feature, the abstractions can initialize a phy_driver structure with zero easily; instead of initializing all the members by hand. It's supposed to be stable in the not so distant future.
Link: rust-lang/rust#116218
Signed-off-by: FUJITA Tomonori fujita.tomonori@gmail.com Reviewed-by: Andrew Lunn andrew@lunn.ch Reviewed-by: Alice Ryhl aliceryhl@google.com Signed-off-by: NipaLocal <nipa@local>
kuba-moo pushed a commit to linux-netdev/testing that referenced this pull request
This patch adds abstractions to implement network PHY drivers; the driver registration and bindings for some of callback functions in struct phy_driver and many genphy_ functions.
This feature is enabled with CONFIG_RUST_PHYLIB_ABSTRACTIONS=y.
This patch enables unstable const_maybe_uninit_zeroed feature for kernel crate to enable unsafe code to handle a constant value with uninitialized data. With the feature, the abstractions can initialize a phy_driver structure with zero easily; instead of initializing all the members by hand. It's supposed to be stable in the not so distant future.
Link: rust-lang/rust#116218
Signed-off-by: FUJITA Tomonori fujita.tomonori@gmail.com Reviewed-by: Andrew Lunn andrew@lunn.ch Reviewed-by: Alice Ryhl aliceryhl@google.com Signed-off-by: NipaLocal <nipa@local>
kuba-moo pushed a commit to linux-netdev/testing that referenced this pull request
This patch adds abstractions to implement network PHY drivers; the driver registration and bindings for some of callback functions in struct phy_driver and many genphy_ functions.
This feature is enabled with CONFIG_RUST_PHYLIB_ABSTRACTIONS=y.
This patch enables unstable const_maybe_uninit_zeroed feature for kernel crate to enable unsafe code to handle a constant value with uninitialized data. With the feature, the abstractions can initialize a phy_driver structure with zero easily; instead of initializing all the members by hand. It's supposed to be stable in the not so distant future.
Link: rust-lang/rust#116218
Signed-off-by: FUJITA Tomonori fujita.tomonori@gmail.com Reviewed-by: Andrew Lunn andrew@lunn.ch Reviewed-by: Alice Ryhl aliceryhl@google.com Signed-off-by: NipaLocal <nipa@local>
kuba-moo pushed a commit to linux-netdev/testing that referenced this pull request
This patch adds abstractions to implement network PHY drivers; the driver registration and bindings for some of callback functions in struct phy_driver and many genphy_ functions.
This feature is enabled with CONFIG_RUST_PHYLIB_ABSTRACTIONS=y.
This patch enables unstable const_maybe_uninit_zeroed feature for kernel crate to enable unsafe code to handle a constant value with uninitialized data. With the feature, the abstractions can initialize a phy_driver structure with zero easily; instead of initializing all the members by hand. It's supposed to be stable in the not so distant future.
Link: rust-lang/rust#116218
Signed-off-by: FUJITA Tomonori fujita.tomonori@gmail.com Reviewed-by: Andrew Lunn andrew@lunn.ch Reviewed-by: Alice Ryhl aliceryhl@google.com Signed-off-by: NipaLocal <nipa@local>
kuba-moo pushed a commit to linux-netdev/testing that referenced this pull request
This patch adds abstractions to implement network PHY drivers; the driver registration and bindings for some of callback functions in struct phy_driver and many genphy_ functions.
This feature is enabled with CONFIG_RUST_PHYLIB_ABSTRACTIONS=y.
This patch enables unstable const_maybe_uninit_zeroed feature for kernel crate to enable unsafe code to handle a constant value with uninitialized data. With the feature, the abstractions can initialize a phy_driver structure with zero easily; instead of initializing all the members by hand. It's supposed to be stable in the not so distant future.
Link: rust-lang/rust#116218
Signed-off-by: FUJITA Tomonori fujita.tomonori@gmail.com Reviewed-by: Andrew Lunn andrew@lunn.ch Reviewed-by: Alice Ryhl aliceryhl@google.com Signed-off-by: NipaLocal <nipa@local>
kuba-moo pushed a commit to linux-netdev/testing that referenced this pull request
This patch adds abstractions to implement network PHY drivers; the driver registration and bindings for some of callback functions in struct phy_driver and many genphy_ functions.
This feature is enabled with CONFIG_RUST_PHYLIB_ABSTRACTIONS=y.
This patch enables unstable const_maybe_uninit_zeroed feature for kernel crate to enable unsafe code to handle a constant value with uninitialized data. With the feature, the abstractions can initialize a phy_driver structure with zero easily; instead of initializing all the members by hand. It's supposed to be stable in the not so distant future.
Link: rust-lang/rust#116218
Signed-off-by: FUJITA Tomonori fujita.tomonori@gmail.com Reviewed-by: Andrew Lunn andrew@lunn.ch Reviewed-by: Alice Ryhl aliceryhl@google.com Signed-off-by: NipaLocal <nipa@local>
kuba-moo pushed a commit to linux-netdev/testing that referenced this pull request
This patch adds abstractions to implement network PHY drivers; the driver registration and bindings for some of callback functions in struct phy_driver and many genphy_ functions.
This feature is enabled with CONFIG_RUST_PHYLIB_ABSTRACTIONS=y.
This patch enables unstable const_maybe_uninit_zeroed feature for kernel crate to enable unsafe code to handle a constant value with uninitialized data. With the feature, the abstractions can initialize a phy_driver structure with zero easily; instead of initializing all the members by hand. It's supposed to be stable in the not so distant future.
Link: rust-lang/rust#116218
Signed-off-by: FUJITA Tomonori fujita.tomonori@gmail.com Reviewed-by: Andrew Lunn andrew@lunn.ch Reviewed-by: Alice Ryhl aliceryhl@google.com Signed-off-by: NipaLocal <nipa@local>
kuba-moo pushed a commit to linux-netdev/testing that referenced this pull request
This patch adds abstractions to implement network PHY drivers; the driver registration and bindings for some of callback functions in struct phy_driver and many genphy_ functions.
This feature is enabled with CONFIG_RUST_PHYLIB_ABSTRACTIONS=y.
This patch enables unstable const_maybe_uninit_zeroed feature for kernel crate to enable unsafe code to handle a constant value with uninitialized data. With the feature, the abstractions can initialize a phy_driver structure with zero easily; instead of initializing all the members by hand. It's supposed to be stable in the not so distant future.
Link: rust-lang/rust#116218
Signed-off-by: FUJITA Tomonori fujita.tomonori@gmail.com Reviewed-by: Andrew Lunn andrew@lunn.ch Reviewed-by: Alice Ryhl aliceryhl@google.com Signed-off-by: NipaLocal <nipa@local>
kuba-moo pushed a commit to linux-netdev/testing that referenced this pull request
This patch adds abstractions to implement network PHY drivers; the driver registration and bindings for some of callback functions in struct phy_driver and many genphy_ functions.
This feature is enabled with CONFIG_RUST_PHYLIB_ABSTRACTIONS=y.
This patch enables unstable const_maybe_uninit_zeroed feature for kernel crate to enable unsafe code to handle a constant value with uninitialized data. With the feature, the abstractions can initialize a phy_driver structure with zero easily; instead of initializing all the members by hand. It's supposed to be stable in the not so distant future.
Link: rust-lang/rust#116218
Signed-off-by: FUJITA Tomonori fujita.tomonori@gmail.com Reviewed-by: Andrew Lunn andrew@lunn.ch Reviewed-by: Alice Ryhl aliceryhl@google.com Signed-off-by: NipaLocal <nipa@local>
kuba-moo pushed a commit to linux-netdev/testing that referenced this pull request
This patch adds abstractions to implement network PHY drivers; the driver registration and bindings for some of callback functions in struct phy_driver and many genphy_ functions.
This feature is enabled with CONFIG_RUST_PHYLIB_ABSTRACTIONS=y.
This patch enables unstable const_maybe_uninit_zeroed feature for kernel crate to enable unsafe code to handle a constant value with uninitialized data. With the feature, the abstractions can initialize a phy_driver structure with zero easily; instead of initializing all the members by hand. It's supposed to be stable in the not so distant future.
Link: rust-lang/rust#116218
Signed-off-by: FUJITA Tomonori fujita.tomonori@gmail.com Reviewed-by: Andrew Lunn andrew@lunn.ch Reviewed-by: Alice Ryhl aliceryhl@google.com Signed-off-by: NipaLocal <nipa@local>
kuba-moo pushed a commit to linux-netdev/testing that referenced this pull request
This patch adds abstractions to implement network PHY drivers; the driver registration and bindings for some of callback functions in struct phy_driver and many genphy_ functions.
This feature is enabled with CONFIG_RUST_PHYLIB_ABSTRACTIONS=y.
This patch enables unstable const_maybe_uninit_zeroed feature for kernel crate to enable unsafe code to handle a constant value with uninitialized data. With the feature, the abstractions can initialize a phy_driver structure with zero easily; instead of initializing all the members by hand. It's supposed to be stable in the not so distant future.
Link: rust-lang/rust#116218
Signed-off-by: FUJITA Tomonori fujita.tomonori@gmail.com Reviewed-by: Andrew Lunn andrew@lunn.ch Reviewed-by: Alice Ryhl aliceryhl@google.com Signed-off-by: NipaLocal <nipa@local>
kuba-moo pushed a commit to linux-netdev/testing that referenced this pull request
This patch adds abstractions to implement network PHY drivers; the driver registration and bindings for some of callback functions in struct phy_driver and many genphy_ functions.
This feature is enabled with CONFIG_RUST_PHYLIB_ABSTRACTIONS=y.
This patch enables unstable const_maybe_uninit_zeroed feature for kernel crate to enable unsafe code to handle a constant value with uninitialized data. With the feature, the abstractions can initialize a phy_driver structure with zero easily; instead of initializing all the members by hand. It's supposed to be stable in the not so distant future.
Link: rust-lang/rust#116218
Signed-off-by: FUJITA Tomonori fujita.tomonori@gmail.com Reviewed-by: Andrew Lunn andrew@lunn.ch Reviewed-by: Alice Ryhl aliceryhl@google.com Signed-off-by: NipaLocal <nipa@local>
kuba-moo pushed a commit to linux-netdev/testing that referenced this pull request
This patch adds abstractions to implement network PHY drivers; the driver registration and bindings for some of callback functions in struct phy_driver and many genphy_ functions.
This feature is enabled with CONFIG_RUST_PHYLIB_ABSTRACTIONS=y.
This patch enables unstable const_maybe_uninit_zeroed feature for kernel crate to enable unsafe code to handle a constant value with uninitialized data. With the feature, the abstractions can initialize a phy_driver structure with zero easily; instead of initializing all the members by hand. It's supposed to be stable in the not so distant future.
Link: rust-lang/rust#116218
Signed-off-by: FUJITA Tomonori fujita.tomonori@gmail.com Reviewed-by: Andrew Lunn andrew@lunn.ch Reviewed-by: Alice Ryhl aliceryhl@google.com Signed-off-by: NipaLocal <nipa@local>
kuba-moo pushed a commit to linux-netdev/testing that referenced this pull request
This patch adds abstractions to implement network PHY drivers; the driver registration and bindings for some of callback functions in struct phy_driver and many genphy_ functions.
This feature is enabled with CONFIG_RUST_PHYLIB_ABSTRACTIONS=y.
This patch enables unstable const_maybe_uninit_zeroed feature for kernel crate to enable unsafe code to handle a constant value with uninitialized data. With the feature, the abstractions can initialize a phy_driver structure with zero easily; instead of initializing all the members by hand. It's supposed to be stable in the not so distant future.
Link: rust-lang/rust#116218
Signed-off-by: FUJITA Tomonori fujita.tomonori@gmail.com Reviewed-by: Andrew Lunn andrew@lunn.ch Reviewed-by: Alice Ryhl aliceryhl@google.com Signed-off-by: NipaLocal <nipa@local>
intel-lab-lkp pushed a commit to intel-lab-lkp/linux that referenced this pull request
This patch adds abstractions to implement network PHY drivers; the driver registration and bindings for some of callback functions in struct phy_driver and many genphy_ functions.
This feature is enabled with CONFIG_RUST_PHYLIB_ABSTRACTIONS=y.
This patch enables unstable const_maybe_uninit_zeroed feature for kernel crate to enable unsafe code to handle a constant value with uninitialized data. With the feature, the abstractions can initialize a phy_driver structure with zero easily; instead of initializing all the members by hand. It's supposed to be stable in the not so distant future.
Link: rust-lang/rust#116218
Signed-off-by: FUJITA Tomonori fujita.tomonori@gmail.com Reviewed-by: Andrew Lunn andrew@lunn.ch Reviewed-by: Alice Ryhl aliceryhl@google.com Signed-off-by: David S. Miller davem@davemloft.net
Comment on lines +570 to +584
fn const_maybe_uninit_zeroed() { |
---|
// Sanity check for `MaybeUninit::zeroed` in a realistic const situation (plugin array term) |
#[repr(C)] |
struct Foo { |
a: Option<&'static str>, |
b: Bar, |
c: f32, |
d: *const u8, |
} |
#[repr(C)] |
struct Bar(usize); |
struct FooPtr(*const Foo); |
unsafe impl Sync for FooPtr {} |
static UNINIT: FooPtr = FooPtr([unsafe { MaybeUninit::zeroed().assume_init() }].as_ptr()); |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what motivated this test but there actually isn't any guarantee that all-zero bytes are a valid value for Option<&'static str>
since that's a fat pointer.
NPO is only guaranteed for thin pointers
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah but just because there is no guarantee doesn't mean we should have no test.
Or put differently, library and ui tests are a rustc implementation detail and not source for stable guarantees. Only docs are stable guarantees.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also we should make that a docs guarantee for &str, as a separate future PR
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That'd conflict with niches-for-metadata that I'm working on. The length field will have a larger niche which means it becomes preferred by the layout algorithm and Option::None is no longer zero but some other value.
That's how I found this.
Or put differently, library and ui tests are a rustc implementation detail and not source for stable guarantees.
I mean that this looks like it has been inspired by some real code and that that code is suspect.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds extremely unfortunate and that a special case should be put back in or something. But we can go into that on zulip or whatever PR you open.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test was just a sanity check that it does indeed do the right thing. I suppose &str
might not have been the best optional reference, but that specific choice wasn't motivated by any real code.
Otoh, it should still zero everything even if invalid, even if Miri one day starts flagging this test.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
error[E0080]: it is undefined behavior to use this value
--> library/core/tests/mem.rs:789:5
|
789 | static UNINIT: FooPtr = FooPtr([unsafe { MaybeUninit::zeroed().assume_init() }].as_ptr());
| ^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>[0].a.<enum-variant(Some)>.0: encountered a null reference
|
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
= note: the raw bytes of the constant (size: 8, align: 8) {
╾───alloc7286<imm>────╼ │ ╾──────╼
}
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otoh, it should still zero everything even if invalid, even if Miri one day starts flagging this test.
...or the compiler itself I suppose. Feel free to change or #[allow(...)]
this test as needed, as long as there isn't any risk of something like MaybeUninit::zeroed()
's output later being fixed up with a non-zero niche in the pointer metadata (seems unlikely)
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even if we never guaranteed NPO for wide pointers, changing that seems very risky and I expect it will break some unsafe code out there. Most people won't expect such a discontinuity between thin and wide ptrs.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turns out the actual problem with this test is that it is UB because the type has padding, so the memory will not be all-zeroes after being returned by assume_init()
. ;)
Reviewers
RalfJung RalfJung left review comments
the8472 the8472 left review comments
Lokathor Lokathor left review comments
scottmcm scottmcm left review comments
lilasta lilasta left review comments
dtolnay dtolnay approved these changes
Labels
Area: Constant evaluation, covers all const contexts (static, const fn, ...)
This issue / PR is in PFCP or FCP with a disposition to merge it.
The final comment period is finished for this PR / Issue.
This PR was explicitly merged by bors.
This change is insta-stable, so needs a completed FCP to proceed.
Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Status: PR is in FCP and is awaiting for FCP to complete.
Relevant to the language team, which will review and decide on the PR/issue.
Relevant to the library API team, which will review and decide on the PR/issue.