-
Notifications
You must be signed in to change notification settings - Fork 9
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
Support unsized data in Gc
#33
Comments
I'm looking at working on this - I don't know the library well enough, but I assume that adding |
You’ll probably need to change the allocation logic as well, since we currently pass by value (not allowed for unsized values). I think the simplest approach is probably to add a new constructor that takes a Box, then reworking the allocation path to handle that case. (And of course changing bounds.) Let me know what you think. I’m @Others on the rust discord as well. Feel free to DM me there if you want to talk through it with me. |
WIP branch: https://github.com/alekratz/shredder/tree/unsized-types On my branch I've added This does appear to accept unsized type declarations, which is great. @Others As far as the new |
Excellent point about deallocation! I think we can adapt "DeallocationStrategy" to solve that issue? Adding a new strategy to indicate it needs reboxed and dropped Note that we won't be able to handle non-'static data with that approach, since dropping a box runs the destructor |
1 similar comment
Excellent point about deallocation! I think we can adapt "DeallocationStrategy" to solve that issue? Adding a new strategy to indicate it needs reboxed and dropped Note that we won't be able to handle non-'static data with that approach, since dropping a box runs the destructor |
I'm working on a function that will go in the pub fn from_box<T: Scan + ?Sized + 'static>(v: Box<T>) -> (Self, *const T) {
let raw_ptr: *const T = Box::into_raw(v);
let scan_ptr: *const (dyn Scan + 'static) = raw_ptr;
todo!()
} But when I compile it, I'm being given errors about how I can't copy
This is confusing to me, because while this is technically true, I'm trying to copy the pointer, not the value itself. Do you know what I'm doing wrong? |
Hmmm I think this is the tricky bit of this issue. Going to write out my full thoughts--apologize if I explain stuff you already know! Your direct issue here is that Rust only lets you make trait objects out of Sized types. This is because making a trait object out of an unsized type is tricky, for example consider if we implemented So let's forget about slices for this issue. Let's limit ourselves to trait objects. Imagine a trait So as far as I can see we have three options to proceed here:
Writing this out while a bit tired, so feel free to drop some questions. |
@Others thanks for the thorough explanation, I had a feeling it had to do with trait objects, sizedness, and how trait objects are represented under the hood. I can't really say I have a good solution either - I'll have to put some thought into it, too. I've also experimented with the idea of using an |
Some other thoughts: the ultimate goal is to be able to allocate a value (sized or otherwise), and then being able to coerce it to an unsized type. That is, this behavior: let value: Gc<MyType> = Gc::new(MyType::new()); // <-- some well-defined struct
let dyn_value: Gc<dyn MyTrait> = value; // <-- assuming MyType implements MyTrait basically accomplishes the same thing, right? There's a couple of nightly-only traits called I feel like I'm skipping over something, but would allow for unsized data in |
I think that for nightly For stable, I think this may still be possible. What about creating a new |
@Others I'm working on implementing a I think the |
@alekratz Yeah totally agree that As far as
|
@Others I figure having the macro would be a nice ergonomics feature, but if you don't think it's necessary, I won't include it. |
Resolved by #45 |
It'd be nice if you could store unsized data in a
Gc
. Not sure how to implement thisThe text was updated successfully, but these errors were encountered: