-
Notifications
You must be signed in to change notification settings - Fork 252
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
Reduce uses of uninitialized arrays #3261
Conversation
3aecd94
to
39380df
Compare
CI fails due to #3263 |
Any comments for this PR? Is the direction good? Can it be merged despite the CI issue? |
Lots of fixes should land since they are good. I hope we'll fix the dav1d situation so we can have back the tests :/ |
39380df
to
36da899
Compare
Codecov ReportAttention:
📢 Thoughts on this report? Let us know!. |
src/asm/shared/transform/inverse.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If all the changes in this PR were like this file, I would approve it in a heartbeat.
This is the pattern we should be following to avoid undefined behavior and double initialization.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand the comment. Does that mean other files than inverse.rs are not acceptable? What do I need to change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, I've wanted to use a pattern of:
let initialized = function(&mut maybe_uninit);
but that required reliably tracking the length inside the function, which would regress performance. This lead me to try some loop optimizations like #3262 but I found it wasn't always possible to have guaranteed length for free. Plus there's A LOT of uninitialized to deal with.
There are more functions using which I haven't converted yet, because I'm not actually sure they fully initialize their data!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Firstly, thank you for detailing the current sites of potential undefined behavior. Everything that maintains the current intent can be merged. Any changes that replace uninitialized()
with zero-fill should be dropped and can be addressed in a follow-up PR.
BTW, I've wanted to use a pattern of:
let initialized = function(&mut maybe_uninit);
I have recently tackled this issue in a toy project:
https://github.com/barrbrain/sudoku/blob/main/src/lib.rs#L27-L40
Some care is required with ownership semantics when crossing the unsafe
boundary. This pattern is well defined:
https://github.com/barrbrain/sudoku/blob/main/src/lib.rs#L355-L356
I will see if we can add some infrastructure to ease converting the current code to well-defined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once MaybeUninit::uninit_array
hits stable I guess a lot would be easier.
Probably we could change some Vec
in Box<[]> to make more evident that the size is fixed meanwhile.
(also, thank you again for taking care of this :))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only cases of zero-fill (I assume you mean from_fn(|| 0)
) are in benchmarks, outside of the benchmarked section. I assume they're not important, since they're neither in the library, nor performance-critical. So I've just changed them for simplicity and determinism.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Sorry that I missed the zero-fill changes were limited to tests and benchmarks.
I'm trying to remove UB of
Aligned::uninitialized()
— #1572