Skip to content

Introduce trait Castable - #8041

Merged
bors-servo merged 5 commits into
servo:masterfrom
nox:castable
Oct 21, 2015
Merged

bors-servo merged 5 commits into
servo:masterfrom
nox:castable

Conversation

@nox

@nox nox commented Oct 15, 2015

Copy link
Copy Markdown
Contributor

Removes all those messy FooCast structures in InheritTypes.rs.

Review on Reviewable

@nox nox added A-content/dom Interacting with the DOM from web content A-content/bindings The DOM bindings I-refactor No impact; the issue is one of maintainability or tidiness. Proposed solution requires refactoring. labels Oct 15, 2015
@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Oct 15, 2015
@highfive

Copy link
Copy Markdown

warning Warning warning

  • These commits modify unsafe code. Please review it carefully!
  • These commits modify layout code, but no reftests are modified. Please consider adding a reftest!

@jdm

jdm commented Oct 15, 2015

Copy link
Copy Markdown
Member

I got through the first two commits.


Reviewed 3 of 3 files at r1, 1 of 1 files at r2.
Review status: 2 of 84 files reviewed at latest revision, all discussions resolved, some commit checks pending.


Comments from the review on Reviewable.io

@eefriedman

Copy link
Copy Markdown
Contributor

It's probably a good idea to always specify the type of downcasts; even if the compiler can technically infer the expected type, it's difficult to read. For example, in one case the type of a downcast is deduced based on the fact that LayoutHTMLInputElementHelpers is the only trait which currently has a method called "get_size_for_layout".

@nox

nox commented Oct 16, 2015

Copy link
Copy Markdown
Contributor Author

@eefriedman I don't think so. The case you found maybe is surprising, but not much more than some Deref coercions we already have all over the place. In other occurrences, removing the type really helps readability:

    fn get_html_element(&self) -> Option<Root<HTMLHtmlElement>> {
        self.GetDocumentElement().and_then(Root::downcast)
    }

@bors-servo

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #8026) made this pull request unmergeable. Please resolve the merge conflicts.

@highfive highfive added S-needs-rebase There are merge conflict errors. and removed S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. labels Oct 16, 2015
@nox nox removed the S-needs-rebase There are merge conflict errors. label Oct 16, 2015
@bors-servo

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #7977) made this pull request unmergeable. Please resolve the merge conflicts.

@highfive highfive added S-needs-rebase There are merge conflict errors. and removed S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. labels Oct 17, 2015
@bors-servo

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #7415) made this pull request unmergeable. Please resolve the merge conflicts.

@highfive highfive added S-needs-rebase There are merge conflict errors. and removed S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. labels Oct 17, 2015
@bors-servo

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #7935) made this pull request unmergeable. Please resolve the merge conflicts.

@highfive highfive added S-needs-rebase There are merge conflict errors. and removed S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. labels Oct 19, 2015
@nox nox removed the S-needs-rebase There are merge conflict errors. label Oct 19, 2015
@bors-servo

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #8095) made this pull request unmergeable. Please resolve the merge conflicts.

@highfive highfive added S-needs-rebase There are merge conflict errors. and removed S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. labels Oct 20, 2015
@nox nox assigned jdm Oct 20, 2015
@jdm jdm removed the S-awaiting-review There is new code that needs to be reviewed. label Oct 20, 2015
@nox

nox commented Oct 20, 2015

Copy link
Copy Markdown
Contributor Author

Review status: all files reviewed at latest revision, 5 unresolved discussions, some commit checks failed.


components/script/dom/bindings/conversions.rs, line 112 [r3] (raw file):
Well, these are conversions. I feel like we should make a round of patches to move around pieces of code, introducing new modules in the process, but that feels a bit out of scope.


components/script/dom/domimplementation.rs, line 118 [r4] (raw file):
What about an expect call? I don't really like assert that actually do important things. I'm pretty sure we have more unwrap calls than we have uses of assert in such cases.


Comments from the review on Reviewable.io

@jdm

jdm commented Oct 20, 2015

Copy link
Copy Markdown
Member

Review status: all files reviewed at latest revision, 5 unresolved discussions, some commit checks failed.


components/script/dom/bindings/conversions.rs, line 112 [r3] (raw file):
File a followup issue, please. Everything else in this file is related to converting to/from JS values.


components/script/dom/domimplementation.rs, line 118 [r4] (raw file):
That's fair. I'd be ok with either

let result = doc_node.AppendChild(doc_type.upcast());
assert!(result.is_ok());

or expect.


Comments from the review on Reviewable.io

nox added 4 commits October 21, 2015 10:59
This method is given a DOMClass value and returns whether it derives from Self.

Interfaces with no descendants directly check whether the given DOMClass is the
same as their own.
This trait is used to hold onto the downcast and upcast functions of all
castable IDL interfaces. A castable IDL interface is one which either derives
from or is derived by other interfaces.

The deriving relation is represented by implementations of marker trait
DerivedFrom<T: Castable> generated in InheritTypes.

/^[ ]*use dom::bindings::codegen::InheritTypes::.*(Base|Cast|Derived)/ {
    /::[a-zA-Z]+(Base|Cast|Derived);/d
    s/([{ ])[a-zA-Z]+(Base|Cast|Derived), /\1/g
    s/([{ ])[a-zA-Z]+(Base|Cast|Derived), /\1/g
    s/, [a-zA-Z]+(Base|Cast|Derived)([},])/\2/g
    s/, [a-zA-Z]+(Base|Cast|Derived)([},])/\2/g
    /\{([a-zA-Z]+(Base|Cast|Derived))?\};$/d
    s/\{([a-zA-Z_]+)\};$/\1;/
}

s/([a-zA-Z]+)Cast::from_ref\(\&?\**([a-zA-Z_]+)(\.r\(\))?\)/\2.upcast::<\1>()/g
s/([a-zA-Z]+)Cast::from_ref\(\&?\**([a-zA-Z_]+)(\.[a-zA-Z_]+\(\))?\)/\2\3.upcast::<\1>()/g
s/\(([a-zA-Z]+)Cast::from_ref\)/\(Castable::upcast::<\1>\)/g

s/([a-zA-Z]+)Cast::from_root/Root::upcast::<\1>/g

s/([a-zA-Z]+)Cast::from_layout_js\(\&([a-zA-Z_.]+)\)/\2.upcast::<\1>()/g

s/([a-zA-Z]+)Cast::to_ref\(\&?\**([a-zA-Z_]+)(\.r\(\))?\)/\2.downcast::<\1>()/g
s/([a-zA-Z]+)Cast::to_ref\(\&?\**([a-zA-Z_]+)(\.[a-zA-Z_]+\(\))?\)/\2\3.downcast::<\1>()/g
s/\(([a-zA-Z]+)Cast::to_ref\)/\(Castable::downcast::<\1>\)/g

s/([a-zA-Z]+)Cast::to_root/Root::downcast::<\1>/g

s/([a-zA-Z]+)Cast::to_layout_js\(&?([a-zA-Z_.]+(\(\))?)\)/\2.downcast::<\1>()/g

s/\.is_document\(\)/.is::<Document>()/g
s/\.is_htmlanchorelement\(\)/.is::<HTMLAnchorElement>()/g
s/\.is_htmlappletelement\(\)/.is::<HTMLAppletElement>()/g
s/\.is_htmlareaelement\(\)/.is::<HTMLAreaElement>()/g
s/\.is_htmlbodyelement\(\)/.is::<HTMLBodyElement>()/g
s/\.is_htmlembedelement\(\)/.is::<HTMLEmbedElement>()/g
s/\.is_htmlfieldsetelement\(\)/.is::<HTMLFieldSetElement>()/g
s/\.is_htmlformelement\(\)/.is::<HTMLFormElement>()/g
s/\.is_htmlframesetelement\(\)/.is::<HTMLFrameSetElement>()/g
s/\.is_htmlhtmlelement\(\)/.is::<HTMLHtmlElement>()/g
s/\.is_htmlimageelement\(\)/.is::<HTMLImageElement>()/g
s/\.is_htmllegendelement\(\)/.is::<HTMLLegendElement>()/g
s/\.is_htmloptgroupelement\(\)/.is::<HTMLOptGroupElement>()/g
s/\.is_htmloptionelement\(\)/.is::<HTMLOptionElement>()/g
s/\.is_htmlscriptelement\(\)/.is::<HTMLScriptElement>()/g
s/\.is_htmltabledatacellelement\(\)/.is::<HTMLTableDataCellElement>()/g
s/\.is_htmltableheadercellelement\(\)/.is::<HTMLTableHeaderCellElement>()/g
s/\.is_htmltablerowelement\(\)/.is::<HTMLTableRowElement>()/g
s/\.is_htmltablesectionelement\(\)/.is::<HTMLTableSectionElement>()/g
s/\.is_htmltitleelement\(\)/.is::<HTMLTitleElement>()/g
@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Oct 21, 2015
@nox nox removed the S-needs-rebase There are merge conflict errors. label Oct 21, 2015
@nox

nox commented Oct 21, 2015

Copy link
Copy Markdown
Contributor Author

@jdm Rebased and addressed, I would appreciate it if I don't need to ever rebase that again. ;)

@nox

nox commented Oct 21, 2015

Copy link
Copy Markdown
Contributor Author

Added a commit to fix #8125.

@jdm

jdm commented Oct 21, 2015

Copy link
Copy Markdown
Member

@bors-servo: r+
https://www.youtube.com/watch?v=FnpJBkAMk44


Reviewed 35 of 35 files at r6.
Review status: all files reviewed at latest revision, 1 unresolved discussion, all commit checks successful.


Comments from the review on Reviewable.io

@bors-servo

Copy link
Copy Markdown
Contributor

📌 Commit d0e022b has been approved by jdm

@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-awaiting-review There is new code that needs to be reviewed. labels Oct 21, 2015
@nox

nox commented Oct 21, 2015

Copy link
Copy Markdown
Contributor Author

@bors-servo p=1

@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Testing commit d0e022b with merge 674589c...

bors-servo pushed a commit that referenced this pull request Oct 21, 2015
Introduce trait Castable

Removes all those messy FooCast structures in InheritTypes.rs.

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8041)
<!-- Reviewable:end -->
@bors-servo

Copy link
Copy Markdown
Contributor

☀️ Test successful - android, gonk, linux-dev, linux-rel, mac-dev-ref-unit, mac-rel-css, mac-rel-wpt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-content/bindings The DOM bindings A-content/dom Interacting with the DOM from web content I-refactor No impact; the issue is one of maintainability or tidiness. Proposed solution requires refactoring. S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants