Skip to content

Use generic associated types for GcHandleSystem #27

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

Closed
wants to merge 1 commit into from

Conversation

Techcable
Copy link
Member

Generic Associated Types significantly cleanup the GcHandleSystem interface, and are nessecarry for the tests to be generic over collectors.

Generic Associated Types have been accepted in Rust RFC #1958. However, much like specialization, they've been kind of in a semi-permenant unstable state for many years (the RFC is from 2016).

I've tried to avoid tying the zerogc API to any nightly features, especially those that are unlikely to be stabalized soon.

However,t the implementations are already making heavy use of nightly, and it doesn't look like it's going away any time soon.

Although I still want to avoid using, in practice it seems silly to avoid using GAT when it cleans up the handle API so significantly.

Unfortunately there is a tiny issue with the implementation right now and there is an error with a where bound in zerogc-context. I hope to fix that eventually.

Unfortunately there is a tiny issue with the implementation
so I'm not pushing this to master just yet.
@Techcable
Copy link
Member Author

Okay, I still think we need to clean up the GcHandleSystem API.

However, I think it might be a good idea to make GcHandle a structure instead of a trait,
where it wraps an internal pointer that implements a RawGcHandle trait.

This will be sort of like the RawVecRepr trait in #29. I think maybe we should wait for that PR first to see how that goes.

pub struct GcHandle<T: GcSafe, Id: CollectorId> {
    raw: Id::RawHandle,
    marker: PhantomData<T>,
}
impl<T: GcSafe, Id: CollectorId> Deref for GcHandle<T> {
    type Target = T;
    fn deref(&self) -> &T {
        unsafe { &*(self.raw.as_ptr() as *const T) }
    }

pub unsafe trait GcRawHandle {
    fn as_ptr(&self) -> *const c_void;
}

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 this pull request may close these issues.

1 participant