Repository navigation
Refactor implementation of TextControl - #19909
Conversation
|
Heads up! This PR modifies the following files:
|
| } | ||
| } | ||
|
|
||
| #[allow(unrooted_must_root)] |
There was a problem hiding this comment.
I'm fairly sure this is "wrong", but I don't know the right way to do it (even after reading this) so I could do with some advice here.
|
Personally the existing implementation doesn't bother me too much, but I do feel that this is better (assuming we can figure out the |
| } | ||
|
|
||
| pub struct TextControlSelection<'a, E: TextControlElement> { | ||
| element: &'a E, |
There was a problem hiding this comment.
So the problem you're facing here is this line. Since the SM GC doesn't trace the Rust stack, it does not know that there is an actively borrowed reference to the HTML{Input, TextArea}Element, and as a result it may collect the element while Rust still has a borrowed reference to it, making it "unsafe".
The solution here is to create a pointer type that SM recognizes and can trace, and there are 2 of them that we can use here: either Dom<T> or DomRoot<T>. I think DomRoot<T> may make more sense here, since all of the uses of the TextControlSelection struct does not bind to any identifier and is treated as a temporary.
There was a problem hiding this comment.
I'm not sure that replacing the type with something else is valuable. Our borrowed pointers to DOM types are fine, because they can only be obtained from properly rooted values. I'm inclined to leave the allow line as it is.
There was a problem hiding this comment.
That is also fine, since I don't think it's actually possible to have the GC collect the element at all in any case.
There was a problem hiding this comment.
I actually tried changing it to use a DomRoot<T>, which took ages to figure out and once I finally got there I still had the unrooted_must_root error... hence I reverted back to what I've submitted here and asked for advice!
|
Tidy failure: |
Thanks. I did run tidy, but I think it didn't catch this because I renamed the file (before deciding to revert to the existing naming). |
The intention here is to make the flow more explicit. I.e. rather than calling `self.dom_select()` and relying on the programmer to know/realise that this method is provided by a trait, we call `self.selection().dom_select()` and the programmer can inspect the definition of `self.selection()` to follow the code. This came out of a discussion with KiChjang here: servo#19544 (comment) Note that I tried to make "selection" be a member field of HTML{Input,TextArea}Element but it opened up a whole can of worms with lifetimes, so it seemed simpler to not do that since it is not essential for this code to work.
3ca0fcb to
0461681
Compare
|
@bors-servo r+ |
|
📌 Commit 0461681 has been approved by |
Refactor implementation of TextControl The intention here is to make the flow more explicit. I.e. rather than calling `self.dom_select()` and relying on the programmer to know/realise that this method is provided by a trait, we call `self.selection().dom_select()` and the programmer can inspect the definition of `self.selection()` to follow the code. This came out of a discussion with KiChjang here: #19544 (comment) Note that I tried to make "selection" be a member field of HTML{Input,TextArea}Element but it opened up a whole can of worms with lifetimes, so it seemed simpler to not do that since it is not essential for this code to work. r? @jdm and @KiChjang <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/19909) <!-- Reviewable:end -->
|
☀️ Test successful - android, arm32, arm64, linux-dev, linux-rel-css, linux-rel-wpt, mac-dev-unit, mac-rel-css1, mac-rel-css2, mac-rel-wpt1, mac-rel-wpt2, mac-rel-wpt3, mac-rel-wpt4, windows-msvc-dev |
The intention here is to make the flow more explicit. I.e. rather than
calling
self.dom_select()and relying on the programmer toknow/realise that this method is provided by a trait, we call
self.selection().dom_select()and the programmer can inspect thedefinition of
self.selection()to follow the code.This came out of a discussion with KiChjang here:
#19544 (comment)
Note that I tried to make "selection" be a member field of
HTML{Input,TextArea}Element but it opened up a whole can of worms with
lifetimes, so it seemed simpler to not do that since it is not
essential for this code to work.
r? @jdm and @KiChjang
This change is