Skip to content

Conversation

@bluss
Copy link
Member

@bluss bluss commented Apr 13, 2020

The trick is simply to traverse the target array using a raw view / raw
pointers; this means we don't create any references to
potentially-uninitialized values.

Assignment *x = y.clone() is used where x is a *mut A, y is a &A;
this will work as intended when A: Copy; assignment should not need that
the value being overwritten, when Copy, is initialized.

Unfortunately we use Zip here instead of the older methods
(zip_mut_with, unordered_foreach_mut); because Zip implements equivalent
functionality but in a generic way. The access pattern and performance
is not guaranteed to be identical.

Related to issue #685

The trick is simply to traverse the target array using a raw view / raw
pointers; this means we don't create any references to
potentially-uninitialized values.

Assignment `*x = y.clone()` is used where x is a *mut A, y is a &A;
this will work as intended when A: Copy; assignment should not need that
the value being overwritten, when Copy, is initialized.

Unfortunately we use Zip here instead of the older methods
(zip_mut_with, unordered_foreach_mut); because Zip implemnets equivalent
functionality but in a generic way. The access pattern and performance
is not guaranteed to be identical.
@bluss
Copy link
Member Author

bluss commented Apr 13, 2020

Benchmarks suggest .fill() is unchanged. Looks like we don't have an assign benchmark.

@bluss
Copy link
Member Author

bluss commented Apr 13, 2020

Source to back us up on that assignment through *x on raw pointer will have the intended effect https://old.reddit.com/r/rust/comments/cefgec/howto_replace_memuninitialized_with_memmaybeuninit/eu87689/

@bluss bluss marked this pull request as draft April 15, 2020 22:18
@bluss
Copy link
Member Author

bluss commented Apr 23, 2020

Thoughts for next time: Rethink - we introduced maybe_uninit instead. But is this still worth doing? Maybe, but need to include new trait AssignElem in the design. Additional trait for overwriting?

@bluss bluss closed this Apr 23, 2020
@bluss bluss deleted the assign-fill-uninit branch April 23, 2020 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants