You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's currently impossible to store DST (Trait object, for example) inside RC:
let x:std::rc::Rc<Reader>;
gives you: the trait 'core::kinds::Sized' must be implemented because it is required by 'alloc::rc::Rc'. However, you can store trait object inside Box. Rc uses Box internally, so it seems inconsistent that one cannot use refcounted box as replacement for Box.
One could work around this issue by storing Box<Trait> inside Rc, but that would incur double indirection.
Moreover, one couldn't implement their own Rc because of related ICE: #17959 .
Quick update, my attempts have halted for the moment. The way I did it appears to have made compiling std cause rustc to enter an infinite loop, and I had added an extra pointer in any case. We may just want to wait for that ICE to be fixed.
There are two pieces missing here: we need coercions of deeply DST objects in order to create Rc<T> and we need to handle drop - the latter uses a bunch of functions, mainly size_of which don't accept ?Sized type params. The rest is just adding ?Sized in a bunch of places (which I have on a branch).
I'm working on spec'ing then implementing the DST coercions atm. I guess #19063 will cover everything that needs doing to implement drop, but I haven't checked that.
Arc has exactly the same issues as Rc (drop and coercions).
FWIW, I have an out of tree implementation of Rc that works with DST. I've mainly tested Rc<str> and Rc<Fn(A, B) -> C> and valgrind seems to be happy with it.
My implementation only supports strong references [1] and uses a different data layout than the one in libstd, which results in a simple implementation of the constructor and the destructor. I have also documented the (re)allocations that each constructor/conversion (e.g. String -> Rc<str>) may require.
[1] I didn't implement weak references because (I think) I don't need them (yet) for what I'm using the Rc for (I don't have to deal with cyclic structures, or have RefCells in my code which AFAIK are required to create them)
Activity
brandonson commentedon Oct 23, 2014
No idea whether we even want to change things before #16918 gets resolved, but I'll work on this just to give me an excuse to dig into the libs again.
little-arhat commentedon Oct 24, 2014
@brandonson FYI, I've tried to fix it by changing RcBox to:
but that didn't work out because of ICE from #17959 .
brandonson commentedon Nov 3, 2014
Quick update, my attempts have halted for the moment. The way I did it appears to have made compiling std cause rustc to enter an infinite loop, and I had added an extra pointer in any case. We may just want to wait for that ICE to be fixed.
steveklabnik commentedon Feb 16, 2015
This also impacts using closures, since they're trait objects.
milibopp commentedon Feb 20, 2015
Shouldn't this include
std::sync::Arc? Or would that be a separate PR?steveklabnik commentedon Feb 20, 2015
It could be the same, the root cause is the same.
nrc commentedon Mar 16, 2015
There are two pieces missing here: we need coercions of deeply DST objects in order to create
Rc<T>and we need to handledrop- the latter uses a bunch of functions, mainlysize_ofwhich don't accept?Sizedtype params. The rest is just adding?Sizedin a bunch of places (which I have on a branch).I'm working on spec'ing then implementing the DST coercions atm. I guess #19063 will cover everything that needs doing to implement
drop, but I haven't checked that.Archas exactly the same issues asRc(drop and coercions).japaric commentedon Apr 2, 2015
FWIW, I have an out of tree implementation of
Rcthat works with DST. I've mainly testedRc<str>andRc<Fn(A, B) -> C>and valgrind seems to be happy with it.My implementation only supports strong references [1] and uses a different data layout than the one in libstd, which results in a simple implementation of the constructor and the destructor. I have also documented the (re)allocations that each constructor/conversion (e.g.
String->Rc<str>) may require.[1] I didn't implement weak references because (I think) I don't need them (yet) for what I'm using the
Rcfor (I don't have to deal with cyclic structures, or haveRefCells in my code which AFAIK are required to create them)huonw commentedon Apr 2, 2015
@japaric cool! Although, fwiw, that sort of pointer (with separate allocation for the refcounts) almost exists today via
Rc<Box<T>>.japaric commentedon Apr 2, 2015
Yes, but that one has double indirection, it's like
Box<Box<Trait>>andBox<String>. Each call toderefhas to go through one layer of indirection.huonw commentedon Apr 2, 2015
Yeah, hence "almost". :)
ftxqxd commentedon May 15, 2015
I believe this was fixed in #24619.
alexcrichton commentedon May 15, 2015
Yay!
Eh2406 commentedon Sep 3, 2017
There is a FIXME related to this issue,
https://github.com/rust-lang/rust/blob/master/src/libcore/tests/hash/mod.rs#L72
Now that the issue is closed can the FIXME be fix, or made more specific?