-
-
Notifications
You must be signed in to change notification settings - Fork 417
Conversion of boxed slices to Arc and IVec #1108
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
Conversation
|
Whoops, I goofed up MSRV, will take another look at Layout construction |
|
Has miri thrown any complaints when run against a variety of sizes? |
|
It looks good. I got a regular old panic when using a ZST, but I fixed that above. |
src/arc.rs
Outdated
| ptr::write( | ||
| &mut dst as *mut _ as *mut *mut u8, | ||
| dst_thin as *mut u8, | ||
| ); |
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.
This is the part that I'm stumbling a bit over. I'm a bit worried that this might break if the internal layout for fat pointers changes. The reason I went with the fatten method from https://users.rust-lang.org/t/construct-fat-pointer-to-struct/29198/9 was because @dtolnay provided it as a way to fatten things without assuming the memory layout. I think I want to avoid this if a later version of Rust changes the internal layout for fat pointers and causes this to break. I'm having trouble knowing if this will also break.
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.
Ah, good point. I can make use of that to write a narrower impl<T> From<Box<[T]>>.
This implementation does not rely on fat pointer layout
75a7e07 to
fc8f9aa
Compare
|
Looks good! Thanks for fixing this! |
This PR rewrites the (unsafe code!)
From<Box<T>> for Arc<T>implementation to allow dynamically sized types, likestd::sync::Arcdoes. Constructing a fat pointer to a dynamically sizedArcInner<T>from a*mut u8thin pointer and the source fat pointer requires some extra gymnastics, see the comments for details. This implementation is then used to add back theFrom<Box<[u8]>> for IVecimplementation. Also included: rewrite of Arc's Debug implementation to allow dynamically sized types, and a small test for the conversion. The unsafe code is modeled after the standard library's code, so it ought to be okay, plus I'm going to run tests with Miri overnight.Fixes #1107