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

Issue #10605 generate unions from Typdefs inner type #12397

Closed
wants to merge 3 commits into from

Conversation

@Scorpil
Copy link
Contributor

Scorpil commented Jul 11, 2016

#11203 follow-up, rebased to current master.


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #10605
  • There are tests for these changes OR
  • These changes do not require tests because _____

This change is Reviewable

@highfive
Copy link

highfive commented Jul 11, 2016

Heads up! This PR modifies the following files:

  • @KiChjang: components/script/dom/bindings/codegen/CodegenRust.py, components/script/dom/bindings/codegen/parser/WebIDL.py, components/script/dom/testbinding.rs, components/script/dom/webidls/TestBinding.webidl
@highfive
Copy link

highfive commented Jul 11, 2016

warning Warning warning

  • These commits modify script code, but no tests are modified. Please consider adding a test!
@emilio
Copy link
Member

emilio commented Jul 11, 2016

Reviewed 3 of 4 files at r1.
Review status: 3 of 4 files reviewed at latest revision, 1 unresolved discussion.


components/script/dom/testbinding.rs, line 573 [r1] (raw file):

    fn FuncControlledMethodDisabled(&self) {}
    fn FuncControlledMethodEnabled(&self) {}
    fn DocumentOrTypedef(&self, _: Option<Option<DocumentOrTypedefTest >>) -> () {}

nit: No space before >>, and the return type can be ellided.


Comments from Reviewable

@jdm
Copy link
Member

jdm commented Jul 11, 2016

@Scorpil Do you use linux? The previous PR stalled after there was a bizarre reproducible build problem only on ubuntu.

@Scorpil
Copy link
Contributor Author

Scorpil commented Jul 11, 2016

@jdm I'm on mac, but trying to reproduce it in virtualbox. As you can see, that problem is still there, so this PR is still WIP.

@emilio
Copy link
Member

emilio commented Jul 11, 2016

I can try to reproduce, though I'm not on Ubuntu.

@KiChjang KiChjang mentioned this pull request Jul 11, 2016
4 of 5 tasks complete
@bors-servo
Copy link
Contributor

bors-servo commented Jul 12, 2016

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

@emilio
Copy link
Member

emilio commented Jul 12, 2016

Ok, so I was able to reproduce it consistently.

I'm not an expert in how WebIDL.py works, so to fix it I did the obvious thing (#12418), and with that and this patch I was able to build! EDIT: I did something stupid, still doesn't build it seems, debugging...

@Scorpil
Copy link
Contributor Author

Scorpil commented Jul 12, 2016

@emilio, should i leave this ticket to you? We're doing same stuff in parallel now.

@emilio
Copy link
Member

emilio commented Jul 12, 2016

@Scorpil: Feel free to investigate, I'm not going to be able to dedicate it a lot of time to be fair.

@Scorpil
Copy link
Contributor Author

Scorpil commented Jul 12, 2016

@emilio ok, let me know if you have something.

@emilio
Copy link
Member

emilio commented Jul 12, 2016

I basically know what's happening, what I don't know is how to solve it.

So the reason we have our own UnionTypes.rs file, is because we generate that once all the other interfaces have been processed. The problem with the approach of this patch is that it relies on the order in which the files are being processed, that diverges between Linux and OSX.

On Linux, if you find a Blob field but you've not processed Blob.webidl yet (that's what unresolved type means), when you try to define a typedef for it, the parser bails out. On OSX it seems to be the case that the TestBinding file is processed after it, so it doesn't fail.

So I see two solutions:

  1. Do nothing. Our bindings already do the correct thing, this is only sugar.
  2. Figure out a way of specifying dependencies between WebIDL files, or doing that automatically. Seems doable but I'm not sure it's worth the effort.

Does that make sense?

@KiChjang
Copy link
Member

KiChjang commented Jul 12, 2016

Doing nothing is not an option. I don't think typing something like DocumentOrBlobOrBufferSourceOrFormDataOrURLSearchParamsOrUSVString is a good alternative to DocumentOrBodyInit, and it breaks expectations, i.e. when I see a WebIDL Document or BodyInit, I should expect to see a Rust enum of DocumentOrBodyInit, not the whole string of what BodyInit represents.

@emilio
Copy link
Member

emilio commented Jul 12, 2016

@KiChjang: What about generating a pub use instead (either on the same file, or on the UnionTypes.rs file? That would be easily doable, and solves the naming problem, sort of.

@KiChjang
Copy link
Member

KiChjang commented Jul 12, 2016

I believe that was tried before, but I think the problem was that none of the enum variants can be referenced that way, i.e.

pub use AOrBOrCOrD as AOrFoo;

// Does not work
let bar = AOrFoo::B(...);
@emilio
Copy link
Member

emilio commented Jul 12, 2016

Are you sure about that? I know it doesn't work with type A = B, but this seems to work just fine.

@Scorpil
Copy link
Contributor Author

Scorpil commented Jul 13, 2016

@emilio , @KiChjang well, we can fix the issue with this easy fix: Scorpil@49cadcd

It's not ideal, as it implicitly enforces file naming convention (if you rename TestBindings.rs to TestBindingsZ.rs it will break again), but it does the job now and will keep feature cross-platform until somebody implements proper file dependency logic.
What do you think?

Here's travis build btw: https://travis-ci.org/Scorpil/servo/jobs/144395789

@Ms2ger
Copy link
Contributor

Ms2ger commented Jul 13, 2016

FWIW, distinct webidl files exist only as source code organization. Conceptually, they're all one big file where order does not matter.

@Scorpil
Copy link
Contributor Author

Scorpil commented Jul 13, 2016

@Ms2ger so we need some kind of "dynamic dispatch" here? I'll see what i can come up with.

@Scorpil Scorpil force-pushed the Scorpil:typedefs branch from 6709c5b to ddcc769 Jul 14, 2016
@KiChjang
Copy link
Member

KiChjang commented Jul 14, 2016

r? @Ms2ger

@emilio
Copy link
Member

emilio commented Jul 14, 2016

The problem with sorting the list IMO is that even more unexpected behavior may appear. For example you can use a union with Blob in the Document idl file, but not the opposite...

@emilio
Copy link
Member

emilio commented Jul 14, 2016

Hadn't seen the last patch actually, but if you change the webidl parser, can you ensure:

  1. - ./mach test-webidl succeeds
  2. - You write a test for the behavior you're changing?

That would make the attempt clearer.

@Scorpil
Copy link
Contributor Author

Scorpil commented Jul 14, 2016

It wasn't related to fileorder after all. Well, maybe it was, but that was not the root of the problem. The bug was in 'complete' method for UnionType that:

  1. Didn't enforce TypedefType completeness
  2. Incorrectly evaluated nested union types
@Scorpil
Copy link
Contributor Author

Scorpil commented Jul 14, 2016

@emilio just tried test-webidl - passed.
You're right, I'll write some tests for this tomorrow or over the weekend.

@KiChjang
Copy link
Member

KiChjang commented Jul 14, 2016

Travis is failing:

$ ./mach test-unit

   Compiling util_tests v0.0.1 (file:///home/travis/build/servo/servo/tests/unit/util)

   Compiling profile_tests v0.0.1 (file:///home/travis/build/servo/servo/tests/unit/profile)

   Compiling style_tests v0.0.1 (file:///home/travis/build/servo/servo/tests/unit/style)

   Compiling net_tests v0.0.1 (file:///home/travis/build/servo/servo/tests/unit/net)

   Compiling net_traits_tests v0.0.1 (file:///home/travis/build/servo/servo/tests/unit/net_traits)

   Compiling gfx_tests v0.0.1 (file:///home/travis/build/servo/servo/tests/unit/gfx)

   Compiling script v0.0.1 (file:///home/travis/build/servo/servo/components/script)

   Compiling layout_tests v0.0.1 (file:///home/travis/build/servo/servo/tests/unit/layout)

/home/travis/build/servo/servo/components/script/dom/testbinding.rs:10:60: 10:81 error: unresolved import `dom::bindings::codegen::Bindings::TestBindingBinding::DocumentOrTypedefTest`. There is no `DocumentOrTypedefTest` in `dom::bindings::codegen::Bindings::TestBindingBinding`. Did you mean to use `documentOrTypedef`? [E0432]

/home/travis/build/servo/servo/components/script/dom/testbinding.rs:10 use dom::bindings::codegen::Bindings::TestBindingBinding::{DocumentOrTypedefTest, TestBindingMethods};

                                                                                                                                  ^~~~~~~~~~~~~~~~~~~~~

/home/travis/build/servo/servo/components/script/dom/testbinding.rs:10:60: 10:81 help: run `rustc --explain E0432` to see a detailed explanation

error: aborting due to previous error

error: Could not compile `script`.

To learn more, run the command again with --verbose.

The command "./mach test-unit" exited with 101.

39.96s$ ./mach test-compiletest

   Compiling compiletest_rs v0.1.3

   Compiling script v0.0.1 (file:///home/travis/build/servo/servo/components/script)

   Compiling compiletest_helper v0.0.1 (file:///home/travis/build/servo/servo/tests/compiletest/helper)

/home/travis/build/servo/servo/components/script/dom/testbinding.rs:10:60: 10:81 error: unresolved import `dom::bindings::codegen::Bindings::TestBindingBinding::DocumentOrTypedefTest`. There is no `DocumentOrTypedefTest` in `dom::bindings::codegen::Bindings::TestBindingBinding`. Did you mean to use `documentOrTypedef`? [E0432]

/home/travis/build/servo/servo/components/script/dom/testbinding.rs:10 use dom::bindings::codegen::Bindings::TestBindingBinding::{DocumentOrTypedefTest, TestBindingMethods};

                                                                                                                                  ^~~~~~~~~~~~~~~~~~~~~

/home/travis/build/servo/servo/components/script/dom/testbinding.rs:10:60: 10:81 help: run `rustc --explain E0432` to see a detailed explanation

error: aborting due to previous error

error: Could not compile `script`.
@Scorpil
Copy link
Contributor Author

Scorpil commented Jul 14, 2016

@KiChjang ugh, just saw it too... This is one strange bug. I'm going to fix it, again, over the next couple of days. You should probably remove awaiting review flair for now.

@emilio
Copy link
Member

emilio commented Jul 14, 2016

@Scorpil fwiw, is it again a linux-only bug?

@Scorpil
Copy link
Contributor Author

Scorpil commented Jul 14, 2016

@emilio yep.

@bors-servo
Copy link
Contributor

bors-servo commented Jul 21, 2016

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

@KiChjang
Copy link
Member

KiChjang commented Aug 1, 2016

@Scorpil Any updates on this?

@Scorpil
Copy link
Contributor Author

Scorpil commented Aug 3, 2016

@KiChjang unfortunately not. At this moment I'm actually struggling to compile servo under linux virtual machine. Getting some strange errors in mozjs compilation. Will try to have an actual update by the end of next week. Is it ok or too long, @KiChjang ?

@jdm
Copy link
Member

jdm commented Aug 3, 2016

You might try running ./mach clean (should only be necessary once) and then ./mach build -j1; those address two of the most common known issues with building mozjs on linux at the moment.

@KiChjang
Copy link
Member

KiChjang commented Aug 12, 2016

@Scorpil Are you planning on finishing this?

@Scorpil
Copy link
Contributor Author

Scorpil commented Aug 16, 2016

@KiChjang I'd like to, but looks like I don't have enough experience with servo to get to the root of this in my free time. Sorry, I'll try to help servo on some other ticket.

@KiChjang KiChjang mentioned this pull request Aug 30, 2016
4 of 4 tasks complete
@KiChjang
Copy link
Member

KiChjang commented Sep 6, 2016

I've rebased this in my branch, and I found out that some new parts of the code was never run at all.

@@ -3860,6 +3878,14 @@ def get_match(name):
else:
arrayObject = None

typedefMemberTypes = filter(lambda t: isinstance(t, IDLTypedefType), memberTypes)
if len(typedefMemberTypes) > 0:

This comment has been minimized.

@KiChjang

KiChjang Sep 6, 2016

Member

For example. typedefMemberTypes was always null, even if I change isinstance(t, IDLTypedefType) to t.isTypedef(), causing the if len(typedefMemberTypes) > 0: body to never be run.

for memberType in t.memberTypes:
if isinstance(memberType, IDLTypedefType):
return True
return False

This comment has been minimized.

@KiChjang

KiChjang Sep 6, 2016

Member

This function here is pointless because none of the types passed in ever reaches the true branch condition.

@@ -3758,6 +3773,9 @@ def getUnionTypeTemplateVars(type, descriptorProvider):
elif type.isPrimitive():
name = type.name
typeName = builtinNames[type.tag()]
elif isinstance(type, IDLTypedefType):
name = type.name
typeName = type.name

This comment has been minimized.

@KiChjang

KiChjang Sep 6, 2016

Member

This branch was also never ran. None of the types passed in was ever an IDLTypedef or IDLTypedefType.

@KiChjang
Copy link
Member

KiChjang commented Sep 6, 2016

As it currently stands right now, the code in these commits do not work as intended, and as such this isn't valuable in keeping open.

@KiChjang KiChjang closed this Sep 6, 2016
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.

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