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 rooting arbitrary types #535

Merged
merged 8 commits into from
Dec 25, 2024
Merged

Conversation

jdm
Copy link
Member

@jdm jdm commented Dec 14, 2024

These changes support servo/servo#34194 by:

  • ensuring crown does not complain about Rooted[Guard]<T> where T is annotated with must_root
  • when dropping a rooted value, make clearing the value opt-in (originally introduced in servo/rust-mozjs@557a1ef)
  • exposing the TraceableTrace trait needed to root arbitrary types

The GCMethods trait was being used in two contexts (Rooted<T> and Heap<T>) but the barrier operation is only relevant for Heap<T>. By splitting them out, we avoid the need to implement unused methods that make reviewers nervous.

@sagudev
Copy link
Member

sagudev commented Dec 14, 2024

The GCMethods trait was being used in two contexts (Rooted and Heap) but the barrier operation is only relevant for Heap. By splitting them out, we avoid the need to implement unused methods that make reviewers nervous.

❤️

when dropping a rooted value, make clearing the value opt-in

Where exactly is this used, I cannot seems to find any.

exposing the TraceableTrace trait needed to root arbitrary types

Can we somehow unify TraceableTrace and Traceable? Something like this:

unsafe impl<T: Traceable> TraceableTrace for T {
   unsafe fn do_trace(&mut self, trc: *mut JSTracer) {
     <Self as Traceable>::trace(self, trc)
   }
 }

Also we definitely want to test rooting of arbitrary types

@jdm
Copy link
Member Author

jdm commented Dec 14, 2024

Where exactly is this used, I cannot seems to find any.

The Drop implementation for RootedGuard.

Can we somehow unify TraceableTrace and Traceable?

I've tried a bunch of different blanket impls like this but the compiler always complains that foreign traits have to be implemented on local types or T needs to be a type variable for a local type. Maybe it would be possible if Traceable and TraceableTrace were defined in the same crate?

@jdm
Copy link
Member Author

jdm commented Dec 14, 2024

Also that particular blanket impls leads to conflicts with duplicate RootKind implementations, because of another blanket impl that involves TraceableTrace.

@sagudev
Copy link
Member

sagudev commented Dec 14, 2024

Where exactly is this used, I cannot seems to find any.

The Drop implementation for RootedGuard.

I would consider that as a consumer, I am asking is there any type that its impl actually returns None.

Maybe it would be possible if Traceable and TraceableTrace were defined in the same crate?

Yes I think that would be needed.

Also that particular blanket impls leads to conflicts with duplicate RootKind implementations, because of another blanket impl that involves TraceableTrace.

I think the problem is that we impl Traceable for some RootKind types, maybe we should remove them and start using TraceableTrace as main tracing trait (Traceable would only exists for easier impl of Tracing on custom types).

@sagudev
Copy link
Member

sagudev commented Dec 14, 2024

No, it will need to go the other way, others should impl TraceableTrace and then we add just few additional impl for Traceable (those who have RootKind).

@jdm
Copy link
Member Author

jdm commented Dec 14, 2024

I would consider that as a consumer, I am asking is there any type that its impl actually returns None.

Right now, no. But it enables rooting arbitrary types in Servo without wrapping them in an Option.

@jdm jdm force-pushed the more-rootable-traceables branch from adc60e7 to 370d001 Compare December 14, 2024 21:01
@jdm
Copy link
Member Author

jdm commented Dec 14, 2024

I moved Traceable to mozjs-sys and was able to remove the duplication between TraceableTrace (now renamed to Rootable) and Traceable. I'm really pleased with how easy it is to make rooted! support arbitrary Rust types now!

@sagudev
Copy link
Member

sagudev commented Dec 15, 2024

I moved Traceable to mozjs-sys and was able to remove the duplication between TraceableTrace (now renamed to Rootable) and Traceable. I'm really pleased with how easy it is to make rooted! support arbitrary Rust types now!

Not exactly what I had in mind, but I think it's better this way!

@jdm
Copy link
Member Author

jdm commented Dec 18, 2024

@sagudev Have you reviewed these changes but forgotten to mark them approved?

@sagudev
Copy link
Member

sagudev commented Dec 18, 2024

@sagudev Have you reviewed these changes but forgotten to mark them approved?

I my mind I considered it OK, but companion PR does not work (might be sccache problem). Given the current state of mozjs being ahead of servo we should wait with landing this until stuff clears out.

@jdm
Copy link
Member Author

jdm commented Dec 19, 2024

Got it!

@sagudev
Copy link
Member

sagudev commented Dec 19, 2024

We can rebase this and companion PR and hope for the best.

@jdm jdm force-pushed the more-rootable-traceables branch from 3162529 to c5ded3c Compare December 24, 2024 03:04
@jdm jdm enabled auto-merge December 24, 2024 03:05
@jdm jdm disabled auto-merge December 24, 2024 03:06
@jdm jdm enabled auto-merge December 25, 2024 07:33
@jdm jdm disabled auto-merge December 25, 2024 07:35
@jdm jdm force-pushed the more-rootable-traceables branch from c5ded3c to 2f26a0e Compare December 25, 2024 07:36
@jdm jdm enabled auto-merge December 25, 2024 07:36
@jdm jdm added this pull request to the merge queue Dec 25, 2024
Merged via the queue into servo:main with commit 1765a7c Dec 25, 2024
27 checks passed
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.

2 participants