Closed SoniEx2 closed 1 year ago
struct MyCells<'id, 'this> {
x: LCell<'id, Foo>,
y: Cell<Option<&'this LCell<'id, dyn Bar>>>,
...
}
or something similar (yeah the Cell<Option<T>>
wrapping is a bit awkward but it's fine really. the main point is that this would be fully zero-cost, unlike the current solution with QCells.)
we're playing around with this idea, and it's not going well so far. :/
I still think it would be better to deconstruct the fat pointer and store a pointer and several vtable pointers and reconstruct the fat pointer on request. I included some links in issue #30. Okay it is more low-level, and perhaps needs more thought to ensure soundness. But trying to do too much in the type system is just adding complexity. I still can't quite get my head around the selfref
API and implementation, although if I work on it more probably I will understand. I would go directly for what you need at a byte level (e.g. pointer to boxed data and a set of vtable pointers), and then build a safe abstraction around that. I know you're trying to build on existing abstractions, but it seems to me that it's just making things harder.
it seems we hit rust-lang/rust#75899 aka rust-lang/rust#50213 so it's not our fault we ran into issues!
but yeah we basically want something fully zero-cost! QCell is not zero-cost enough! LCell on the other hand is supposed to get optimized out.
nevertheless, this is far more flexible than #30, and also far more flexible than "just going directly for the vtable pointers". tho it's certainly still suboptimal for just storing the vtable pointers, but aside from that it lets you have LCell
s and move them (or, well, a Pin<Box<_>>
to them) around. (like, the owner is carried with the LCells, instead of having to setup a single-use scope. note that both LCellOwner::scope
and generativity only support single-use scopes, while this selfref
hack is meant to be reusable.)
so this works with unsizing now huh. :p
we've published a crate, no idea if it's sound, but feel free to play with it. https://users.rust-lang.org/t/soundness-review-request-srce-0-1/87587
we've rolled this up into selfref
so we guess we can close this now
would it be possible to have a cell type which is similar to
LCell
, but is based around theselfref
crate?(maybe with
generativity
? we're not familiar with that crate)this is related to #30 but more general
specifically we want a thread-safe lock-free
&mut SelfRefCellEnvironment
which opens a reusable LCell-like environment.