Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@divergentdave
Copy link
Collaborator

This PR rewrites the (unsafe code!) From<Box<T>> for Arc<T> implementation to allow dynamically sized types, like std::sync::Arc does. Constructing a fat pointer to a dynamically sized ArcInner<T> from a *mut u8 thin pointer and the source fat pointer requires some extra gymnastics, see the comments for details. This implementation is then used to add back the From<Box<[u8]>> for IVec implementation. 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

@divergentdave
Copy link
Collaborator Author

Whoops, I goofed up MSRV, will take another look at Layout construction

@divergentdave divergentdave mentioned this pull request Jun 23, 2020
@spacejam
Copy link
Owner

Has miri thrown any complaints when run against a variety of sizes?

@divergentdave
Copy link
Collaborator Author

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,
);
Copy link
Owner

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.

Copy link
Collaborator Author

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
@divergentdave divergentdave force-pushed the david_arc_dst_impls branch from 75a7e07 to fc8f9aa Compare July 1, 2020 01:38
@divergentdave divergentdave marked this pull request as draft July 1, 2020 16:13
@divergentdave divergentdave marked this pull request as ready for review July 1, 2020 23:56
@spacejam
Copy link
Owner

spacejam commented Jul 3, 2020

Looks good! Thanks for fixing this!

@spacejam spacejam merged commit 4119b53 into spacejam:master Jul 3, 2020
@divergentdave divergentdave deleted the david_arc_dst_impls branch November 15, 2020 19:31
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.

From<Box<[u8]>> for IVec

2 participants