Skip to content

Propagate CanGc from Document::new()#33386

Merged
jdm merged 2 commits intoservo:mainfrom
last-genius:can_gc
Sep 9, 2024
Merged

Propagate CanGc from Document::new()#33386
jdm merged 2 commits intoservo:mainfrom
last-genius:can_gc

Conversation

@last-genius
Copy link
Copy Markdown
Contributor

Following #33140 and #33144, more work on marking functions that can transitively trigger a GC to easier recognize hazards.


@last-genius
Copy link
Copy Markdown
Contributor Author

There are a few autogenerated things that I couldn't figure how to modify: VirtualX trait methods, and Document::Open, which somehow autogenerates both Open and Open_ methods (only one of them can GC as of now). This PR has by no means fully propagated CanGc from Document::new, there's still a lot of work to be done.

Another issue I wanted to ask about is whether I should make CanGc Copy or Clone, given that this PR has quite a few functions that call several canGc functions in turn, and currently CanGc::note() instead of can_gc has to be used on all but the first invocation (same if a function calls a canGc func in a loop, etc.), potentially complicating diffs for future changes.

@jdm
Copy link
Copy Markdown
Member

jdm commented Sep 9, 2024

Good question about the moved value! Yes, we should derive copy and clone to make passing it around as easy as possible.

Copy link
Copy Markdown
Member

@jdm jdm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really helpful! Let's add the copy derive and remove a bunch of the CanGc::note calls, and then let's merge this!

fn drop(&mut self) {
if let Some(load) = self.load.take() {
self.doc.finish_load(load);
self.doc.finish_load(load, CanGc::note());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a really interesting result from this work! I would not have assumed that dropping a LoadBlocker value could cause a JS GC, and it's neat that this PR makes that more clear.

@jdm
Copy link
Copy Markdown
Member

jdm commented Sep 9, 2024

Actually, to reduce the risk of merge conflicts let's merge this as-is and do the derive and replacements in a followup.

@jdm jdm added this pull request to the merge queue Sep 9, 2024
Merged via the queue into servo:main with commit e5150db Sep 9, 2024
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