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

Add a marker trait for non GC types #109

Open
ZainlessBrombie opened this issue Nov 30, 2020 · 10 comments
Open

Add a marker trait for non GC types #109

ZainlessBrombie opened this issue Nov 30, 2020 · 10 comments

Comments

@ZainlessBrombie
Copy link

ZainlessBrombie commented Nov 30, 2020

It would be nice to have the following:

  1. An unsafe trait called "GcDeadEnd" (or something), marking something as having no Gc dependencies.
  2. impl GcDeadEnd for e.g. String, primitives, Rc, RefCell etc.
    3) impl Trace for GcDeadEnd

Cheers! :)

@Manishearth Manishearth changed the title Suggestion: Implement Trace for various non-reference types such as Rc<String> Add a marker trait for non GC types Nov 30, 2020
@Manishearth
Copy link
Owner

Currently we just achieve this by a blank Trace impl. A problem is that coherence kinda rears its head if you add a Trace blanket impl based on GcDeadEnd.

@ZainlessBrombie
Copy link
Author

Sorry, could you elaborate what you mean by "coherence kinda rears its head"?

@ZainlessBrombie
Copy link
Author

Additional note: There would be impl Trace for Rc where T: GcDeadEnd
(Things like Gc)

@Manishearth
Copy link
Owner

Sorry, could you elaborate what you mean by "coherence kinda rears its head"?

You'd need a blanket impl Trace for GcDeadEnd impl, and this locks out certain Trace impls from existing due to coherence.

Additional note: There would be impl Trace for Rc where T: GcDeadEnd

You won't be able to have both this and an impl Trace for non-deadend contents.

@ZainlessBrombie
Copy link
Author

ZainlessBrombie commented Dec 2, 2020

Right thanks. I realized:
A) impl Trace for GcDeadEnd is not needed. We only need:
-> impl GcDeadEnd for e.g. String
-> seperate Trace for String
-> impl GcDeadEnd for e.g. Rc<GcDeadEnd>
-> impl Trace for Rc<GcDeadEnd>
B) This still means that we need specialization. (The soundness of which has not been entirely figured out unfortunately)

But with specialization it works in my fork :)
Edit: Just in case you are wondering: Lazy me just included #![feature(specialization)] unconditionally in my fork because I didn't put a #[cfg] on the default-impls ^^

@ZainlessBrombie
Copy link
Author

Nevermind, implemented my own Gc using safe non-experimental Rust only over at https://github.com/ZainlessBrombie/rs-safe-gc
Still missing the derive macro, but it's 3 am ^^
It does not encounter the problem mentioned here and allows moving out of Gc'ed values, a major painpoint for me.

🎉 c:
Either way, hats of to you and all of the Rust core team, I'm already addicted haha ;)

@ZainlessBrombie
Copy link
Author

Ah right I forgot: I'm running an MIT license and used some small snippets of your code (macros, thanks!), is that compatible with your license? I think not... off the top of your head, do you know if that's much of a problem here?

@Manishearth
Copy link
Owner

is that compatible with your license? I think not... off the top of your head, do you know if that's much of a problem here?

yeah that's fine

@andersk
Copy link
Collaborator

andersk commented Dec 28, 2020

Even without specialization, a GcDeadEnd trait could still be used for a checked version of manual unsafe_ignore_trace annotations, right? (I recognize unsafe_ignore_trace is not literally unsafe as per #52, but there’s still value in checking that these annotations don’t cause leaks.)

@Manishearth
Copy link
Owner

Even without specialization, a GcDeadEnd trait could still be used for a checked version of manual unsafe_ignore_trace annotations, right?

Proc macros don't have access to trait information, though I guess we could generate assertions if people are still annotating them.

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

No branches or pull requests

3 participants