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

Do not use borrowed types in the selectors::Element trait. #23463

Closed
wants to merge 1 commit into from
Closed

Do not use borrowed types in the selectors::Element trait. #23463

wants to merge 1 commit into from

Conversation

RazrFalcon
Copy link
Contributor

@RazrFalcon RazrFalcon commented May 26, 2019

This change allows implementing the selectors::Element trait for types that doesn't support borrowed types, like rc-tree.



This change is Reviewable

@highfive
Copy link

Thanks for the pull request, and welcome! The Servo team is excited to review your changes, and you should hear from @asajeffrey (or someone else) soon.

@highfive
Copy link

Heads up! This PR modifies the following files:

  • @emilio: components/style/dom_apis.rs, components/style/rule_collector.rs, components/style/selector_map.rs, components/style/bloom.rs, components/style/sharing/mod.rs and 2 more

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label May 26, 2019
@highfive
Copy link

warning Warning warning

  • These commits modify style code, but no tests are modified. Please consider adding a test!

@@ -58,10 +58,21 @@ pub trait Element: Sized + Clone + Debug {

fn is_html_element_in_html_document(&self) -> bool;

fn local_name(&self) -> &<Self::Impl as SelectorImpl>::BorrowedLocalName;
fn local_name_hash(&self) -> u32;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is ugly. I know. We need three methods instead of one now...

Copy link
Member

Choose a reason for hiding this comment

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

I think we don't need get_local_name or get_namespace, instead fn local_name and fn namespace should move to TElement (in components/style/dom.rs).

@@ -226,7 +226,7 @@ impl SelectorMap<Rule> {
}
});

if let Some(rules) = self.local_name_hash.get(rule_hash_target.local_name()) {
if let Some(rules) = self.local_name_hash.get(&rule_hash_target.get_local_name()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This method invokes clone() now. Which is bad. By I don't know how to fix it.

Copy link
Member

Choose a reason for hiding this comment

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

This doesn't need to use selectors::Element. You can move the fn local_name signature to TElement. So selectors doesn't need get_local_name, and this shouldn't need to call clone().

Copy link
Member

@emilio emilio left a comment

Choose a reason for hiding this comment

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

Thanks for the patch! Needs some changes, I think it can be simpler.

@@ -226,7 +226,7 @@ impl SelectorMap<Rule> {
}
});

if let Some(rules) = self.local_name_hash.get(rule_hash_target.local_name()) {
if let Some(rules) = self.local_name_hash.get(&rule_hash_target.get_local_name()) {
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't need to use selectors::Element. You can move the fn local_name signature to TElement. So selectors doesn't need get_local_name, and this shouldn't need to call clone().

f(element.local_name().get_hash());
f(element.namespace().get_hash());
f(element.local_name_hash());
f(element.namespace_hash());
Copy link
Member

Choose a reason for hiding this comment

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

Same, this doesn't need to use selectors::Element, and selectors doesn't need Element::namespace_hash.

@@ -58,10 +58,21 @@ pub trait Element: Sized + Clone + Debug {

fn is_html_element_in_html_document(&self) -> bool;

fn local_name(&self) -> &<Self::Impl as SelectorImpl>::BorrowedLocalName;
fn local_name_hash(&self) -> u32;
Copy link
Member

Choose a reason for hiding this comment

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

I think we don't need get_local_name or get_namespace, instead fn local_name and fn namespace should move to TElement (in components/style/dom.rs).

@@ -90,8 +90,7 @@ impl Invalidation {
// This could look at the quirks mode of the document, instead
// of testing against both names, but it's probably not worth
// it.
let local_name = element.local_name();
return *local_name == **name || *local_name == **lower_name;
return element.has_local_name(name) || element.has_local_name(lower_name);
Copy link
Member

Choose a reason for hiding this comment

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

Similarly this shouldn't need to change.

@@ -42,7 +42,7 @@ pub fn containing_shadow_ignoring_svg_use<E: TElement>(
loop {
let host = shadow.host();
let host_is_svg_use_element =
host.is_svg_element() && host.local_name() == &*local_name!("use");
host.is_svg_element() && host.has_local_name(&local_name!("use"));
Copy link
Member

Choose a reason for hiding this comment

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

these don't need to change, but may be nicer this way, your call.


if target.namespace() != candidate.element.namespace() {
trace!("Miss: Namespace");
if !target.is_same_type(&candidate.element) {
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't need to change either, and I'd prefer to keep the two checks to remain separate to see why it fails.

&self,
local_name: &<Self::Impl as ::selectors::SelectorImpl>::BorrowedLocalName,
) -> bool {
self.element.has_local_name(local_name)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure it this is correct.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, this is right, local name / namespace don't change.

@@ -877,6 +877,12 @@ pub trait TElement:
hints: &mut V,
) where
V: Push<ApplicableDeclarationBlock>;

/// Returns element's local name.
fn local_name(&self) -> &LocalName;
Copy link
Member

Choose a reason for hiding this comment

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

This still needs to use the Borrowed* gunk, so that you don't break Firefox.

Also this actually needs to be implemented, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure what exact type should be used?

Yes. It's used in the code.

@RazrFalcon
Copy link
Contributor Author

Finally, I was able to build it locally without any errors.

@RazrFalcon
Copy link
Contributor Author

@emilio ?

Copy link
Member

@emilio emilio left a comment

Choose a reason for hiding this comment

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

Yeah, sorry for the lag.

This looks great, thanks! But I need to fix the Firefox implementation as well in servo/components/style/gecko/wrapper.rs.

So I'll land this after #23456 lands, if you don't mind.

Thanks again!

@RazrFalcon
Copy link
Contributor Author

Thanks. No problem.

@emilio
Copy link
Member

emilio commented Jun 3, 2019

I'm cherry-picking this in the next sync

@emilio
Copy link
Member

emilio commented Jun 3, 2019

#23503 includes this commit along with the Firefox changes needed. Thanks a lot for the patch @RazrFalcon!

@emilio emilio closed this Jun 3, 2019
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request Jun 4, 2019
…it. r=emilio

This cherry-picks servo/servo#23463 with a few fixes for
the Gecko build.
emilio pushed a commit to emilio/servo that referenced this pull request Jun 4, 2019
lissyx pushed a commit to lissyx/mozilla-central that referenced this pull request Jun 4, 2019
…it. r=emilio

This cherry-picks servo/servo#23463 with a few fixes for
the Gecko build.
bors-servo pushed a commit that referenced this pull request Jun 4, 2019
style: sync changes from mozilla-central

See each individual commit for details. This also cherry-picks #23463 with a few fixes that were needed in Gecko-only code.

<!-- 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/23503)
<!-- Reviewable:end -->
bors-servo pushed a commit that referenced this pull request Jun 4, 2019
style: sync changes from mozilla-central

See each individual commit for details. This also cherry-picks #23463 with a few fixes that were needed in Gecko-only code.

<!-- 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/23503)
<!-- Reviewable:end -->
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this pull request Oct 4, 2019
…it. r=emilio

This cherry-picks servo/servo#23463 with a few fixes for
the Gecko build.

UltraBlame original commit: 53a5f4a6e1de21b62be288cac96763aeece78277
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this pull request Oct 4, 2019
…it. r=emilio

This cherry-picks servo/servo#23463 with a few fixes for
the Gecko build.

UltraBlame original commit: 53a5f4a6e1de21b62be288cac96763aeece78277
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this pull request Oct 4, 2019
…it. r=emilio

This cherry-picks servo/servo#23463 with a few fixes for
the Gecko build.

UltraBlame original commit: 53a5f4a6e1de21b62be288cac96763aeece78277
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-awaiting-review There is new code that needs to be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

selectors::Element without borrowed types
4 participants