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

Conversation

@RazrFalcon
Copy link
Contributor

RazrFalcon commented May 26, 2019

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


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #22972

This change is Reviewable

@highfive
Copy link

highfive commented May 26, 2019

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

highfive commented May 26, 2019

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
Copy link

highfive commented May 26, 2019

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;

This comment has been minimized.

@RazrFalcon

RazrFalcon May 26, 2019

Author Contributor

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

This comment has been minimized.

@emilio

emilio May 26, 2019

Member

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()) {

This comment has been minimized.

@RazrFalcon

RazrFalcon May 26, 2019

Author Contributor

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

This comment has been minimized.

@emilio

emilio May 26, 2019

Member

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 left a comment

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()) {

This comment has been minimized.

@emilio

emilio May 26, 2019

Member

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());

This comment has been minimized.

@emilio

emilio May 26, 2019

Member

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;

This comment has been minimized.

@emilio

emilio May 26, 2019

Member

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);

This comment has been minimized.

@emilio

emilio May 26, 2019

Member

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"));

This comment has been minimized.

@emilio

emilio May 26, 2019

Member

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) {

This comment has been minimized.

@emilio

emilio May 26, 2019

Member

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)

This comment has been minimized.

@RazrFalcon

RazrFalcon May 26, 2019

Author Contributor

Not sure it this is correct.

This comment has been minimized.

@emilio

emilio May 26, 2019

Member

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;

This comment has been minimized.

@emilio

emilio May 26, 2019

Member

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

Also this actually needs to be implemented, right?

This comment has been minimized.

@RazrFalcon

RazrFalcon May 26, 2019

Author Contributor

Not sure what exact type should be used?

Yes. It's used in the code.

@RazrFalcon
Copy link
Contributor Author

RazrFalcon commented May 27, 2019

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

@RazrFalcon
Copy link
Contributor Author

RazrFalcon commented May 29, 2019

@emilio
emilio approved these changes May 29, 2019
Copy link
Member

emilio left a comment

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

RazrFalcon commented May 29, 2019

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 added 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 added 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 added 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
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

4 participants
You can’t perform that action at this time.