Skip to content
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 types #4

Open
Jesterhearts opened this issue Dec 11, 2021 · 0 comments
Open

Support unsized types #4

Jesterhearts opened this issue Dec 11, 2021 · 0 comments
Labels
enhancement New feature or request

Comments

@Jesterhearts
Copy link
Owner

Jesterhearts commented Dec 11, 2021

Right now, the nodes only allow sized types to be stored. The major reason for this is the coercion
that happens inside the destructor to an unsized type so that the collectors can store heterogenous
lists of nodes, which forces our destructor to require T: Sized.

We could hid Inner<_> behind a trait, and solve the problem that way, but I don't like hiding the
strong counts and live status behind a vtable. Devirtualizers & modern cpus are smart it enough this
might not be an issue though. It would just need benchmarking.

We could store two pointers Inner<T> and Inner<dyn Tracable>, but this seems like a lot of overhead.

If rust-lang #65991 was stable, we could
parameterize GetData on T and try upcasting:

trait Traceable {}

impl<T: ?Sized> Traceable for T {}

trait GetData<T: ?Sized>: Traceable {
    fn get(&self) -> &T;
}

impl<T: ?Sized > GetData<T> for T {
    fn get(&self) -> &T {
        self
    }
}

fn main() {
    let x: std::rc::Rc<usize> = std::rc::Rc::new(10);
    // This works, yay!
    let y: std::rc::Rc<dyn GetData<usize>> = x.clone();
    // But this will fail because of https://github.com/rust-lang/rust/issues/65991
    // let z: std::rc::Rc<dyn Traceable> = y.clone();
}

There are ways to make this appear to work using nasty transmutes on pointers to pointers, but it's
pretty unclear if they're valid (or will remain valid).

I have yet to find a better way despite many attempts :( I'm hoping I've missed something obvious.

@Jesterhearts Jesterhearts added the enhancement New feature or request label Dec 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant