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

Garbage collected trace objects (dyn Trace) #15

Closed
andersk opened this issue Dec 22, 2020 · 2 comments
Closed

Garbage collected trace objects (dyn Trace) #15

andersk opened this issue Dec 22, 2020 · 2 comments

Comments

@andersk
Copy link

andersk commented Dec 22, 2020

The current Trace trait is not object-safe, so it can’t be used with trait objects:

trait Foo: Trace {
    fn foo(&self);
}

#[derive(Trace)]
struct AnyFoo(dyn Foo);

Could it be made object-safe by turning the associated constants into functions and moving the V: GcVisitor type parameter of Trace::visit<V> up to Trace<V>::visit?

@Techcable
Copy link
Member

Oh man ☹️ Based on my experiments today, this is hard to do right.

I really don't want to parameterize Trace like Trace<V: GcVisitor>.

I've played around with having a separate set of DynTrace and DynGcVisitor taits (kind of like erased-serde) but its hard to write blanket impls over regular Trace/GcVisitor traits because they expect statically visible type info.

I'm starting to think maybe I should go closer to the approach you suggested and modify Trace and GcVisitor to be object safe directly.
I really want to keep support for NEEDS_TRACE, but that is hard to do since associated constants aren't supported on trait objects 😦 There is no way to add a special where Self: Sized bound. Maybe I can move it to a separate trait and then specialize?

Kind of just throwing out random suggestions here. This project is still a little experimental 😄 😉

This is related to #16 because both arrays and trait objects are ?Sized.

Techcable added a commit that referenced this issue Dec 29, 2020
We need a better solution!
See issue #15

This reverts commit afcc179.
Techcable added a commit that referenced this issue Jan 10, 2021
This works because `str` is `!Sized` and the blanket impl
for `&T` has an implicit bound `T: Trace`.
TODO: Proper support for unsized types (#15)
@Techcable
Copy link
Member

The new Pointee type and the nightly ptr_metadata API may significantly change this. (See rust-lang/rust#81513)

I'm hesitant to refactor the API design to depend so heavily on a nightly feature, however that may be the only way I can reasonably implement this feature.

In practice, however, zerogc is already limited to nightly because the simple collector requires nightly (although this is mostly for convenience at this point).

@Techcable Techcable changed the title Trace trait is not object-safe Garbage collected trace objects (dyn Trace) Jul 6, 2021
Techcable added a commit that referenced this issue Jul 10, 2021
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 a pull request may close this issue.

2 participants