Uh oh!
There was an error while loading. Please reload this page.
Deprecate uninit_array - #101179
Conversation
rust-highfive
commented
Aug 30, 2022
(rust-highfive has picked a reviewer for you, use r? to override) |
SUPERCILEX
commented
Aug 30, 2022
r? @RalfJung |
This comment has been minimized.
This comment has been minimized.
Uh oh!
There was an error while loading. Please reload this page.
RalfJung
commented
Aug 30, 2022
No objections from my side, but this should go through t-libs. |
thomcc
commented
Aug 30, 2022
I don't feel that strongly here, but I'm not sure I'm a fan of this removal. I've used Even if it doesn't have a performance benefit over |
thomcc
commented
Aug 30, 2022
Actually, now that I look carefully the |
RalfJung
commented
Aug 30, 2022
|
clarfonthey
commented
Aug 31, 2022
My gut feeling is also against this, although I feel like the MaybeUninit methods for arrays could use an upgrade. What if instead of using a method like this, we just directly implemented |
SUPERCILEX
commented
Aug 31, 2022
How would this work when you're trying to read initialized memory? Furthermore, I don't see your suggestion as incompatible with this PR: we still want to nuke this method since the language is now capable of expressing |
clarfonthey
commented
Aug 31, 2022
In terms of deleting this method, keep in mind that it's not yet doable entirely with safe code, since |
SUPERCILEX
commented
Aug 31, 2022
That's actually not true, see how to do it in this docs update: 54014b7#diff-5e72af2fe825c2180f437d54adbdbb19bb40a9cc82bc6c53c2d993d72b08ce3fR149
Forgot that those returned references. This was already attempted (#88837), but I can commit to giving it another spin and then we can nuke the last method in this tracking issue. |
clarfonthey
commented
Aug 31, 2022
I would be in favour of doing that, especially if we can make arrays and slices work as expected without any dedicated methods. In terms of deletion, even though this is unstable, I do think that we should deprecate it for a few weeks before outright removing it, since I and a lot of people have been using this method. This has been done before and feels pretty reasonable in this case. |
SUPERCILEX
commented
Sep 1, 2022
Seems pretty reasonable, done. |
hatzka-nezumi
commented
Sep 2, 2022
This technique isn't possible with a generic. fnfoo<T>() -> [MaybeUninit<T>;4]{constUNINIT_T:MaybeUninit<T> = MaybeUninit::uninit();// E0401[UNINIT_T;4]} |
SUPERCILEX
commented
Sep 2, 2022
Dang, that's a bummer. Haven't had a chance to dig further, but assuming there's no way around this I still think deprecation + removal should move forward since you need to be on nightly to use this feature anyway. To address an earlier comment, I'm not seeing the "but you need to switch to another unstable feature" as a valid counterpoint without further evidence. You could say that other feature might not be stabilized and so we'll need to bring this back, but:
|
RalfJung
commented
Sep 2, 2022
https://github.com/RalfJung/inline-const works even when there are generics. But anyway, the main point above was:
|
clarfonthey
commented
Sep 2, 2022
This is why I proposed adding This still doesn't provide a dedicated operation to "transpose" the uninit and array parts of the type, but it provides the same functionality without having to sacrifice readability. |
SUPERCILEX
commented
Sep 2, 2022
I think a transpose is more valuable than index methods since you can convert back and forth as needed. So is the conclusion that we should do that first before this PR? |
clarfonthey
commented
Sep 2, 2022
I don't think that transposing is a good idea because it makes it unclear which version of the transpose is preferred, and simply giving the option to make the top-level version usable seems preferable. Otherwise, we end up having several different ways of doing things without a clear reason to use one or another, which feels clunky. |
| } | ||
| let mut array = MaybeUninit::uninit_array::<N>(); | ||
| let mut array = MaybeUninit::uninit().transpose(); |
There was a problem hiding this comment.
Is it worth adding a type annotation?
| letmut array = MaybeUninit::uninit().transpose(); | |
| letmut array = MaybeUninit::<[???;N]>::uninit().transpose(); |
There's a lot of inference going on here making the code quite hard to follow.
There was a problem hiding this comment.
Hmmm, yeah I was wondering about this too. My reasoning for this being ok was that if the compiler manages to infer the types then I don't need to think about them. I'm guessing this is flawed because if you have no constraints at all, then the compiler will happily give you an i32. An interesting question arises: are integers and floats the only two places where the compiler will ever pull a type out of its 🍑 if there are no constraints? If so, my gut feeling is that we should get rid of that behavior (separate discussion, I know) since not having 🍑 types would let you do what I'm doing now where I say, "well, the compiler did some inferences so whatever the types are they must be correct". Or maybe I'm thinking too hard about this and type annotations would make human consumption easier (though I'm still curious about the above questions).
There was a problem hiding this comment.
In safe code I tend to follow the same approach -- if the compiler found a type that makes it all work, then that seems right (but I will still sometimes add type annotations to make the code more readable).
In unsafe code though, I don't like trusting the compiler like that. Types are much less meaningful in unsafe code (that's why the code is unsafe to begin with), so IMO type inference should only be relied upon for absolutely obvious cases -- which this one is not.
m-ou-se
commented
Oct 18, 2022
I don't think we should try to maintain any sort of stability for nightly features. The point of nightly features is that they're experimental and that we can change or remove them at any time.
Agreed
This RFC seems relevant: rust-lang/rfcs#3318 |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
m-ou-se
commented
Oct 18, 2022
We briefly discussed this in the libs-api meeting. We prefer removing the function over deprecating it, since it's unstable. |
m-ou-se
commented
Oct 18, 2022
The sentiment in the libs-api meeting was that the array version is actually easier to understand than the |
clarfonthey
commented
Oct 19, 2022
I still would like to express my discomfort with transposes as… exposing something more generic for the sake of it, instead of promoting a good API. Right now we have the major hurdle that there have to be different methods for working with arrays, slices, and values. This doesn't actually solve this problem; in order to work with an array, you're still expected to transpose after the initial IMHO, we can remove this entirely by simply letting people slice directly into a This is the main reason why I promoted deprecating the old method as a compromise: if we're going to offer transposes, it seems worthwhile to see if users will actually prefer it. By removing the alternative, everyone's forced to move back to it instead, which just results in more frustration, IMHO. The one downside of this, which I will admit is rather large, is the fact that the metadata of the unsized value "escapes" from the |
SUPERCILEX
commented
Oct 19, 2022
Absolutely agree that this sucks, that's what I'm trying to improve.
Not sure how that's possible since Also, I still think you'd need transpose APIs because you'll be passed in an |
apiraino
commented
Nov 29, 2022
hello, visiting and checking progress. By skimming the comment history I'm unclear on the status. Perhaps some design work from the author (cc @SUPERCILEX) ? Can anyone provide an update? :) thanks! |
SUPERCILEX
commented
Nov 29, 2022
I still think this will go through, but we're now potentially waiting on inline const stabilization: rust-lang/libs-team#122 (comment) |
Add MaybeUninit array transpose From impls See discussion in rust-lang/rust#101179 and rust-lang/rust#96097. I believe this solution offers the simplest implementation with minimal future API regret. `@RalfJung` mind doing a correctness review?
SUPERCILEX
commented
Jul 27, 2024
Closing as this made progress elsewhere: #96097 (comment) |
Now that #98304 has gone through,
uninit_arrayshould be removed since creating a const array is the One True Way of doing things.Tracking issue: #96097
Closes#66845
Blocked on: rust-lang/libs-team#122 (comment)