Experiment with making various GC things' methods unsafe if not rooted #13

Open
fitzgen opened this Issue Feb 22, 2015 · 2 comments

Comments

Projects
None yet
1 participant
@fitzgen
Owner

fitzgen commented Feb 22, 2015

Need to manually remember to root stuff, at the moment. Would be better if you had to explicitly opt into using an unrooted GC thing.

My fear is that this is going to involve a lot of boilerplate, because each safe version will have to be implemented explicitly.

This is essentially what we have now (although those methods aren't marked unsafe):

    struct SomeGcThing { ... }

    impl SomeGcThing {
        unsafe some_method(&self) { ... }
        unsafe some_other_method(&self) { ... }
    }

    type SomeGcThingPtr = ArenaPtr<SomeGcThing>;
    type RootedSomeGcThing  = Rooted<ArenaPtr<SomeGcThing>>;

However, with the changes implemented here, we would have to add a safe version on RootedSomeGcThing for every unsafe method on SomeGcThing:

    impl RootedSomeGcThing {
        fn some_method(&self) {
            unsafe {
                return (*self).some_method();
            }
        }

        fn some_other_method(&self) {
            unsafe {
                return (*self).some_other_method();
            }
        }
    }

Perhaps macros can help out with this syntactic boilerplate?

@fitzgen

This comment has been minimized.

Show comment
Hide comment
@fitzgen

fitzgen Feb 22, 2015

Owner

Another approach would be to not make ArenaPtr<T> implement Deref, but instead have an unsafe as_ref and as_mut_ref and then Rooted<T> could be the one to implement Deref with an internal unsafe block for wrapping as_ref.

Need to figure out how RootedValue fits in with this, as it doesn't wrap ArenaPtr directly.

Owner

fitzgen commented Feb 22, 2015

Another approach would be to not make ArenaPtr<T> implement Deref, but instead have an unsafe as_ref and as_mut_ref and then Rooted<T> could be the one to implement Deref with an internal unsafe block for wrapping as_ref.

Need to figure out how RootedValue fits in with this, as it doesn't wrap ArenaPtr directly.

@fitzgen

This comment has been minimized.

Show comment
Hide comment
@fitzgen

fitzgen Feb 22, 2015

Owner

Another approach would be to not make ArenaPtr implement Deref, but instead have an unsafe as_ref and as_mut_ref and then Rooted could be the one to implement Deref with an internal unsafe block for wrapping as_ref.

This is essentially implementing http://doc.rust-lang.org/std/ptr/trait.PtrExt.html and http://doc.rust-lang.org/std/ptr/trait.MutPtrExt.html for ArenaPtr.

Owner

fitzgen commented Feb 22, 2015

Another approach would be to not make ArenaPtr implement Deref, but instead have an unsafe as_ref and as_mut_ref and then Rooted could be the one to implement Deref with an internal unsafe block for wrapping as_ref.

This is essentially implementing http://doc.rust-lang.org/std/ptr/trait.PtrExt.html and http://doc.rust-lang.org/std/ptr/trait.MutPtrExt.html for ArenaPtr.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment