script: Pass down &mut JSContext in servoparser and event loop.#42635
script: Pass down &mut JSContext in servoparser and event loop.#42635sagudev merged 3 commits intoservo:mainfrom
&mut JSContext in servoparser and event loop.#42635Conversation
2f451c9 to
49f7da4
Compare
TimvdLippe
left a comment
There was a problem hiding this comment.
Since these PRs are usually big, most of them are atomic changes and thus I am okay to approve. But this one also introduces several usages of temp_gc. I would prefer to take a slower pace with tackling such blockers, before we make wide-sweeping changes. What do you think?
| if self.upcast::<Node>().is_connected_with_browsing_context() { | ||
| debug!("iframe srcdoc modified while in browsing context."); | ||
| self.process_the_iframe_attributes(ProcessingMode::NotFirstTime, can_gc); | ||
| let mut cx = unsafe { temp_cx() }; |
There was a problem hiding this comment.
Same here, let's tackle this first and then update the other ones.
I do not consider In the future I will try to make smaller PRs (I think biggest mistake here was that I went into servoparser instead of just putting temp_cx). |
Is it too big of a hassle to do this anyway? E.g. you start over this patch and use temp_cx in this one place? That would make me a lot more comfortable approving such a PR. Right now, I don't feel comfortable approving given its size and impact. Especially since I am still learning about this migration and you pointed out a couple of things in the devtools PR that I missed. |
|
If it were easy enough I would already split off while doing the PR as I usually do. This time unfortunately I went too deep 😞.
The changes are mostly mechanical so it's usually enough for me to just skim those, but I am very biased here as this is something I am very familiar with as I wrote these new types we use here.
Are you aware of https://gist.github.com/sagudev/839382e70631b1eaed5a4d226b830b6e (linked from #40600)? Tho I find it easier to review code I've also write/use, so I invite you try it (if you have time). Here is good starting point: #42638 |
|
I'm interested in this since it quite overlaps with what's needed to continue #42640. servo/components/script/dom/node.rs Line 2725 in c13d8a2 |
I can open a PR to do it. |
Feel free to do it. |
|
I did try to port VirtualMethod::attribute_mutate (not done but it's it is very involved and cannot be reasonably splited 😞) and we desperately need changes from here, so I will rebase this (we should be able to remove some temp_cx) and hopefully we can land this now. |
d46e4f4 to
eb05147
Compare
|
We were also able to remove some temp_cx from #42681. |
TimvdLippe
left a comment
There was a problem hiding this comment.
I am still torn on what to do with this PR. On the one hand, I still find it unreasonably too large. It makes sense that you want to target the microtask checkpoint and for that a lot needs to happen, but I am not convinced that everything needs to be done in one go.
For example, the changes you made to Range, XMLHttpRequest or Element are all part of #42638 and imo we should tackle that first.
That said, I also know you have spent a considerable amount of time on this already. So there is a sunken cost fallacy here and I don't want to unnecessarily block this work, given that this migration is worthwhile.
Therefore, I propose a middle-ground: Can you separate the following changes from your PR as part of #42638 ? The remaining bits, we then tackle in this PR and merge this in one go.
- components/script/dom/audio/audiocontext.rs
- components/script/dom/audio/mediaelementaudiosourcenode.rs
- components/script/dom/html/htmliframeelement.rs (except the
temp_cxchanges) - components/script/dom/html/htmlimageelement.rs (except the
temp_cxchanges) - components/script/dom/html/htmlmediaelement.rs (except the
temp_cxchanges) - components/script/dom/html/htmlscriptelement.rs
- components/script/dom/dissimilaroriginwindow.rs
- components/script/dom/document.rs (the DOM facing API's)
- components/script/dom/domparser.rs
- components/script/dom/element.rs
- components/script/dom/range.rs
- components/script/dom/shadowroot.rs
- components/script/dom/xmlhttprequest.rs
That's still a huge chunk of work that we can commit in isolation of the other changes. Since these are all similar (they are part of the DOM-facing API migration), that should also be a lot easier to review, since its all mechanical. What we are then left with are the ones that relate to the microtask checkpoint queue and thus we can look closely at this, without the cluttering of the rest.
Thanks again for your patience and contributions. Please know that I am trying to figure out a way forward that helps both you as an author and us as reviewers.
|
TBH I never viewed changes #42638 as standalone (usually they are driven by other changes). I will see what can be done, but I can already tell that dissimilaroriginwindow.rs will not go as it depends on some other window stuff (it is part of separate commit, so we can drop it - that leaves us it one more temp_cx). |
split from servo#42635 Signed-off-by: sagudev <[email protected]>
split from #42635, some dom methods are also called from other function, which require passing down cx from many more places :( Testing: Just refactor, but should be covered by WPT. Part of #42638 Signed-off-by: sagudev <[email protected]>
eb05147 to
666419d
Compare
split from servo#42635, some dom methods are also called from other function, which require passing down cx from many more places :( Testing: Just refactor, but should be covered by WPT. Part of servo#42638 Signed-off-by: sagudev <[email protected]>
TimvdLippe
left a comment
There was a problem hiding this comment.
Went through it and I think it's fine. I left some comments for the usages of temp_cx, please file actionable issues for these. We are taking some shortcuts in this PR with the temp_cx to be able to keep on going with the migration. That's fine by me, but I then would urge us to pick up these tasks first for removing the temp_cx, before we chug along with the migration.
Therefore, let's focus on these vtable usages and get the foundation sorted. Once those are tackled, I reckon that unblocking the other DOM methods will be a lot more straightforward as well.
Do you mind filing these issues and add the TODO-comments in this PR? Then feel free to land this PR. Thanks for taking it on!
| fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation, can_gc: CanGc) { | ||
| #[expect(unsafe_code)] | ||
| fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation, _can_gc: CanGc) { | ||
| let mut cx = unsafe { temp_cx() }; |
There was a problem hiding this comment.
Can you file a new issue explaining the steps required to make this happen? Then we can add it as a // TODO(<issue-number>) here so we don't forget to clean it up.
Btw I consider this part of #42638 since its all touching DOM-facing API's. Therefore, I do think #42638 is an enabler for the kinds of cleanups you do in this PR.
There was a problem hiding this comment.
Yeah, but the problem is that we then need to wait for a lot of dom methods to get this and some dom methods are called from those functions behind traits so we get circular problem (one could say chicken and egg problem). Also we generally do not need all dom methods ported, but it's hard to decide which ones we need. The idea with the migration is that I do mostly harder/tricky stuff and left some easier stuff for others.
There was a problem hiding this comment.
I understand that and I agree it is a solid strategy for this migration. Especially for those circular problems, temp_cx is an appropriate temporary measure. What I am trying to say is: let's try to keep the number of shortcuts we have at the same time at a manageable level. If we take on too much tech debt with those temp fixes, we might do more damage. It's a balancing act and I would prefer us to take a cautious approach when deciding how many shortcuts to take on. If we have (like in this PR), then we have to.
There was a problem hiding this comment.
Btw, I still approve this PR. So feel free to land as-is if you also desire to do so. I would prefer to file the GitHub issues first and add TODO's, but can also do that later. Since this PR touches many points, it has high odds of running into merge conflicts.
There was a problem hiding this comment.
Yeah, I will add issues it was just really busy day yesterday so I was only able to do some work for servo during short breaks.
| fn unbind_from_tree(&self, context: &UnbindContext, can_gc: CanGc) { | ||
| self.super_type().unwrap().unbind_from_tree(context, can_gc); | ||
|
|
||
| let mut cx = unsafe { temp_cx() }; |
There was a problem hiding this comment.
Same here, which seems to be local to Node methods, but doesn't look all that bad at a first glance.
| self.update_the_image_data(can_gc); | ||
| #[expect(unsafe_code)] | ||
| fn adopting_steps(&self, old_doc: &Document, _can_gc: CanGc) { | ||
| let mut cx = unsafe { temp_cx() }; |
|
|
||
| #[expect(unsafe_code)] | ||
| fn process_response(&mut self, _: RequestId, metadata: Result<FetchMetadata, NetworkError>) { | ||
| let mut cx = unsafe { temp_cx() }; |
There was a problem hiding this comment.
Same here. Although this one looks very tricky, given it involves fetch and thus the network code?
There was a problem hiding this comment.
I did *_eof and it's entrypoints were eventloop and tasks so it is easy enough.
Signed-off-by: sagudev <[email protected]>
this was bigger then I hoped Signed-off-by: sagudev <[email protected]>
Signed-off-by: sagudev <[email protected]>
666419d to
4459b9a
Compare
I only wanted to get
&mut JSContextin microtask chunk and checkpoint, but this in turn needed&mut JSContextin servoparser, which then caused need for even more changes in script.I tried to limit the size by putting some
temp_cxin:LoadBlocker,GenericAutoEntryScriptVirtualMethodsFetchResponseListenerTesting: Just refactor, but should be covered by WPT tests.
Part of #40600