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

[idlharness.js] Simplify handling of inheritance and mixins #28650

Merged
merged 1 commit into from Apr 26, 2021

Conversation

foolip
Copy link
Member

@foolip foolip commented Apr 22, 2021

Handling of these concepts was more complicated than (now) necessary.

No changes in the actual test results are intended.

Inheritance:

There's no reason to record inheritance separately in IdlArray's
this.["inheritance"], since it can be determined just as easily
from this.members via the member.base attributes.

The concept of "consequential interfaces" in Web IDL went away with
implements statements in whatwg/webidl#433
and here in #28619.
traverse_inherited_and_consequential_interfaces() can be replaced
with just get_inheritance_stack().

While this changes the behavior of default_to_json_operation(), there
is no toJSON operation declared in a mixin in interfaces/, only in
resources/ tests, so this change should not affect real tests.

default_to_json_operation.html was updated along the lines of simplified
examples in the spec: whatwg/webidl#980

Mixins:

For valid A includes B statements, A is always an interface and
B is always an interface mixin, so there are no include chains or
the possibility of cycles. recursively_get_includes() assumed this.

Instead just save the includes statements found in this.includes
and apply them in merge_mixins, similar to partials.

The handling of partials isn't changed, but collapse_partials is
renamed to merge_partials to match the above.

Not today:

Further unification of partials and mixins is possible, and the handling
of [Exposed] is missing for mixins, but this is left for later.

@foolip foolip changed the title [idlharness.js] Simplify handling of partials and mixins [idlharness.js] Simplify handling of inheritance, partials and mixins Apr 23, 2021
@foolip foolip changed the title [idlharness.js] Simplify handling of inheritance, partials and mixins [idlharness.js] Simplify handling of inheritance and mixins Apr 23, 2021
@foolip foolip force-pushed the foolip/idlharness-partials-includes branch from 5f8cfa6 to 185f655 Compare April 23, 2021 07:29
@foolip foolip marked this pull request as ready for review April 23, 2021 07:29
@wpt-pr-bot wpt-pr-bot requested a review from jgraham April 23, 2021 07:29
@foolip
Copy link
Member Author

foolip commented Apr 23, 2021

@Ms2ger I expect tests will still fail here, but initial review would still be great.

@foolip foolip force-pushed the foolip/idlharness-partials-includes branch from 185f655 to 63f11bc Compare April 23, 2021 07:50
Handling of these concepts was more complicated than (now) necessary.

No changes in the actual test results are intended.

Inheritance:

There's no reason to record inheritance separately in `IdlArray`'s
`this.["inheritance"]`, since it can be determined just as easily
from `this.members` via the `member.base` attributes.

The concept of "consequential interfaces" in Web IDL went away with
`implements` statements in whatwg/webidl#433
and here in #28619.
`traverse_inherited_and_consequential_interfaces()` can be replaced
with just `get_inheritance_stack()`.

While this changes the behavior of `default_to_json_operation()`, there
is no `toJSON` operation declared in a mixin in interfaces/, only in
resources/ tests, so this change should not affect real tests.

default_to_json_operation.html was updated along the lines of simplified
examples in the spec: whatwg/webidl#980

Mixins:

For valid `A includes B` statements, `A` is always an interface and
`B` is always an interface mixin, so there are no include chains or
the possibility of cycles. `recursively_get_includes()` assumed this.

Instead just save the `includes` statements found in `this.includes`
and apply them in `merge_mixins`, similar to partials.

The handling of partials isn't changed, but `collapse_partials` is
renamed to `merge_partials` to match the above.

Not today:

Further unification of partials and mixins is possible, and the handling
of [Exposed] is missing for mixins, but this is left for later.
@foolip foolip force-pushed the foolip/idlharness-partials-includes branch from 63f11bc to 18bea8b Compare April 24, 2021 10:50
* interface B : C {};
*
* results in this["inheritance"] = { A: "B", B: "C" }
* Both this.partials and this.includes will be the objects as parsed by
Copy link
Member Author

Choose a reason for hiding this comment

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

As hinted at in the commit message, it would be natural to add this.mixins and not wrap mixins in IdlInterface at all. But not yet.

@@ -249,11 +234,15 @@ IdlArray.prototype.internal_add_dependency_idls = function(parsed_idls, options)
const new_options = { only: [] }

const all_deps = new Set();
Object.values(this.inheritance).forEach(v => all_deps.add(v));
// NOTE: If 'A includes B' for B that we care about, then A is also a dep.
Copy link
Member Author

Choose a reason for hiding this comment

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

This comment was misleading, there is no "that we care about" condition here.

assert_false('K' in idlArray.members, 'K should be ignored');
// L inherits F, so should be picked up.
Copy link
Member Author

Choose a reason for hiding this comment

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

This comment and the assert description was wrong, now fixed.

assert_array_equals([...map.values()].map(v => v.idlType), ["DOMString", "long"]);
}, 'should return a properly ordered map that accounts for mixed-in interfaces which declare a [Default] toJSON operation.');

test(function() {
Copy link
Member Author

Choose a reason for hiding this comment

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

These tests are just more convoluted forms of the earlier tests IMHO. Order, the non-inheritance of toJSON and the (now correct) mixin behavior is tested above.

@foolip
Copy link
Member Author

foolip commented Apr 24, 2021

@Ms2ger fixing the resources/ tests revealed that I had changed the order (fixed by add .reverse()) and I went down a rabbit hole with whatwg/webidl#979, but now I think it's all in order. It could still be simplified more, but not all in one PR.

Copy link
Contributor

@Ms2ger Ms2ger left a comment

Choose a reason for hiding this comment

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

Haven't done a particularly deep review, but this all seems fine.

var map = new Map(), isDefault = false;
this.traverse_inherited_and_consequential_interfaces(function(I) {
this.get_inheritance_stack().reverse().forEach(function(I) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This made me a little nervous because reverse operates in-place, and get_inheritance_stack doesn't signal very clearly that it returns a fresh array. It seems all is fine, though.

Followup: of the three callers of get_inheritance_stack, one only calls it for the side effects and the two others iterate backward. Maybe change get_inheritance_stack to return the array reversed already?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll send a follow-up to rename it to get_reverse_inheritance_stack.

Copy link
Member Author

Choose a reason for hiding this comment

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

@foolip foolip merged commit b1f27e8 into master Apr 26, 2021
@foolip foolip deleted the foolip/idlharness-partials-includes branch April 26, 2021 08:16
foolip added a commit that referenced this pull request Apr 26, 2021
foolip added a commit that referenced this pull request Apr 26, 2021
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request May 8, 2021
…nce_stack() do the reversing, a=testonly

Automatic update from web-platform-tests
[idlharness.js] Let get_reverse_inheritance_stack() do the reversing (#28688)

As suggested by Ms2ger in web-platform-tests/wpt#28650 (comment)
--

wpt-commits: 11c46de0abfbe7bc728bb55cf2dd020fe0ec949e
wpt-pr: 28688
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants