Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upParse webIDL from compiler plugin to verify inheritance of DOM objects matches IDL #20461
Comments
|
Hi, would that be a good first task? If so I would be interested. |
|
I do not believe this would be a good first task. |
|
@jdm How much additional time would be spent on compilation if we perform this check? |
|
No idea! |
|
Hmm, so my concern is that we already have CodegenRust.py that runs a python lexer and a parser in order to generate WebIDL bindings in our source code. Running another Rust WebIDL lexer and parser seems wasteful to me... unless the idea is to eventually replace the python one? |
|
@jdm I would like to work on this issue. Please let me know if you think I can do it. Thanks! |
|
@jdm I am still interested to work on this issue, if it is available. |
|
Sorry, I was on vacation for all of April. There are four main parts to this project:
|
|
As to @KiChjang's concerns about compilation time, if we can get this working I think we should figure out how long this check takes in isolation, and whether it affects overall build time significantly. |
|
Ok, great I will start working on that. Can you assign the issue to me? Thanks! |
|
@jdm I have read the rust docs for Attributes and Procedural Macros and I just want to clarify a few things to make sure I understand correctly. I have taken bullet 1 to mean add a #[webidl] Token to the attributes set in the existing dom_struct macro, like so. Based on the code in unrooted_must_root.rs, the new plugin will then check for the new webidl attribute using the LateContext.tcx.has_attr function. Please let me know if I have misinterpreted anything, otherwise I will start on the compiler plug-in, thanks! |
|
That is correct. |
|
@jdm I have made the skeleton for the compiler plugin (based on unrooted_must_root.rs). I added a new file verify_webidl.rs and modified lib.rs. First, based on the must_root plugin, I chose the LateLintPass trait for WebIdlPass, however I wanted to check if that is correct since there are other LintPass variants that could be used. Additionally, I thought that I should define the function check_struct_def, since this should give access to both the attributes of the struct (to check for webidl attribute) and the string field which is the parent interface name as a TyStr. That should be the only function to implement for WebIdlPass as far as I can tell. If the above is correct, I will start to work on the actual opening, parsing and checking of the webidl file. Thanks! |
|
@aeweston98 The logic in your verify_webidl.rs makes sense, though I think you can get the DefId of the struct itself by calling cx.tcx.hir.local_def_id. Have you made any further progress on this? |
|
@KiChjang I am in school right now, so I have been busy for a little while and haven't had a chance to progress further. I would like to continue working on it now, if that is ok. |
|
Ack, I'm sorry for missing the previous comment. You are welcome to continue working on it :) |
|
@jdm Sorry for the slow progress. The past few weeks have been very busy with midterms and co-op interviews. I have been making some progress on using the webidl crate to parse the files. I will try to have some results and/or questions by the end of the weekend. Thanks! |
|
@Manishearth Is this redundant with the PR you merged recently? |
|
Yes, however mine is a somewhat hacky bridge between the Rust codegen and Python codegen, so improving it would be nice. But not much of a priority. |
|
@aeweston98 Are you still working on this? |
|
@KiChjang No I am not actively working on it |
This is #21105 |
|
@highfive assign me |
|
Hey @krk! Thanks for your interest in working on this issue. It's now assigned to you! |
|
I have a draft PR checking the first field of Example error:
Definition of servo/components/script/dom/xrviewport.rs Lines 12 to 14 in 1720454 How should I handle the |
|
@krk If the WebIDL interface does not have a parent, then yes, we should check whether the first field is a |
|
@KiChjang After requiring servo/components/script/dom/bindings/codegen/CodegenRust.py Lines 2205 to 2208 in a14b952
|
|
Interesting! The WindowProxy declaration can probably move to WindowProxy.webidl; I'm not really sure why it was put there originally. And the TestBindingProxy issue looks like a legitimate bug. |
|
I have moved |
|
Search for I declared it as #[dom_struct]
pub struct TestBindingProxy {
testbinding_: TestBinding,
}Finally, |
Webidl lint Parse webidl files and lint for inheritance correctness. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #20461 <!-- 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/23200) <!-- Reviewable:end -->
Given this crate, we could theoretically add a compiler plugin that iterates over the types in script::dom::types, parses the WebIDL file that matches that type name, and verifies that the first field of the DOM type matches the name of the parent type of the interface, per the documentation.