Skip to content

webidl: add support for partial interfaces and mixins #460

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

Merged
merged 4 commits into from
Jul 14, 2018

Conversation

ohanar
Copy link
Member

@ohanar ohanar commented Jul 12, 2018

Fixes #246 and #255.

This is a major change to how webidl is processed. This adds
a two phase process, where the first phase records the names of
various types and indexes the mixins (and might do more in the
future). The actual program building happens in the second phase.

As part of this, this also makes it so that interface objects
are passed by reference, rather than by value. The spec isn't
exactly clear on this, but Mozilla's C++ reflection suggestions
seem to indicate that they should be passed by reference (see
https://developer.mozilla.org/en-US/docs/Mozilla/WebIDL_bindings).

This is a major change to how webidl is processed. This adds
a two phase process, where the first phase records the names of
various types and indexes the mixins (and might do more in the
future). The actual program building happens in the second phase.

As part of this, this also makes it so that interface objects
are passed by reference, rather than by value. The spec isn't
exactly clear on this, but Mozilla's C++ reflection suggestions
seem to indicate that they should be passed by reference (see
https://developer.mozilla.org/en-US/docs/Mozilla/WebIDL_bindings).
@ohanar ohanar requested a review from fitzgen July 12, 2018 02:51
}
}

impl<'a, 'b> WebidlParse<&'a FirstPass<'b>> for webidl::ast::Interface {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd personally recommend avoiding the WebidlParse trait entirely as this looks like it may be getting a little too verbose, but otherwise perhaps the FirstPass parameter could be part of the trait signature to avoid the wordiness of lifetimes here?

Copy link
Member

Choose a reason for hiding this comment

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

+1 for FirstPass as part of the trait signature, since pretty much every impl is using it.

@@ -44,14 +44,14 @@ fn method() {
let pi = Foo::new(3.14159).unwrap();
let e = Foo::new(2.71828).unwrap();
// TODO: figure out why the following doesn't fail
Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW this should be fixed now in upstream rust if you wanna do a drive-by cleanup as well

@alexcrichton
Copy link
Contributor

Seems like a great cleanup to me and a good way to structure it as well!

Copy link
Member

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

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

This is a really nice (and overdue!) refactoring! Thanks so much @ohanar :)

I think we can eventually (not in this PR for sure!) also port my hacky is-this-imported-name-defined-or-not analysis to just use FirstPass data, too.

Couple nitpicks I'd like to see addressed before merging, but again this is really great. Thanks!


let mut first_pass = FirstPass::default();
for def in definitions {
if let Definition::Interface(Interface::NonPartial(NonPartialInterface { name, .. })) = def
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick: stylistically I'd prefer using a match with a _ arm to a series of if lets.

raw_ident(&format!("__widl_f_{}_{}", rust_name, ns))
};
#[derive(Default)]
pub struct FirstPass<'a> {
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 a doc comment here explaining what the first pass over the WebIDL does, what information is collected, and for what use and why would be very valuable for future code readers and contributors.

) -> Option<backend::ast::ImportFunction> {
let ret = match self.webidl_ty_to_syn_ty(ty, TypePosition::Return) {
None => {
warn!("Attribute's type does not yet support reading: {:?}", ty);
Copy link
Member

Choose a reason for hiding this comment

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

Should this warning message s/reading/returning/ ?

Copy link
Member

Choose a reason for hiding this comment

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

I guess this is how it was before, but the message no longer makes sense to me, and I assume I originally wrote it...

}
}

impl<'a, 'b> WebidlParse<&'a FirstPass<'b>> for webidl::ast::Interface {
Copy link
Member

Choose a reason for hiding this comment

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

+1 for FirstPass as part of the trait signature, since pretty much every impl is using it.

@ohanar
Copy link
Member Author

ohanar commented Jul 14, 2018

I ended up moving out the new first pass into a new module, and restructuring the new code a bit to make it more extensible in the future. Let me know if you have any new feedback, I hope to finish up addressing your previous comments tomorrow.

Copy link
Contributor

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

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

Looks great! It looks like everything was take care of though? Were there still pieces you wanted to take care of?

Copy link
Member

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

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

This is looking super great, and I think we can land further improvements in new PRs, so I am going to merge this now.

Thanks so much @ohanar ! :)

@fitzgen fitzgen merged commit 1e32e91 into rustwasm:master Jul 14, 2018
@ohanar ohanar deleted the webidl_partial_mixins branch July 15, 2018 00:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants