Skip to content

Support adding Idlharness dependencies - #10381

Merged
lukebjerring merged 10 commits into
web-platform-tests:masterfrom
lukebjerring:idlharness-dependencies
May 17, 2018
Merged

lukebjerring merged 10 commits into
web-platform-tests:masterfrom
lukebjerring:idlharness-dependencies

Conversation

@lukebjerring

@lukebjerring lukebjerring commented Apr 9, 2018 •

Copy link
Copy Markdown
Contributor

This is a request for feedback on a potential solution to #10347

The PR adds a new idlharness.js api: add_dependency_idls(raw_idls, options)

EDIT: Explanation:
Currently, to get idl_array to stop complaining about missing interface definitions, the test author has a couple options:

  • Add all the idl interfaces that get referenced, one by one, using the {only: 'Foo'} helper
  • Add all the idl interfaces and some that aren't referenced, whole file at a time (e.g. html / dom)
  • "mock" the idl interfaces with inline, empty definitions, e.g. interface Foo {};

This PR aims to add a better, 4th option: Add all the idl that get referenced (and nothing more!), whole file at a time. It's better because real interfaces are used, without bloating the test.

Usage examples are in the couple of modified tests.

Note that the options object was needed for adding deps in some cases, because some interfaces are re-declared in both html and dedicated-workers.idl, e.g. WorkerNavigator.
See https://github.com/w3c/web-platform-tests/blob/master/budget-api/interfaces.any.js for example.


This change is Reviewable

@birtles birtles left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Changes to the web-animations tests look good to me.

@foolip foolip left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Cool! Last time I tried to review this I was confused about what it was trying to do, reading more carefully I conclude that it's to pull in untested dependencies from unparsed IDL but filtering out that which nothing depends on, in order to get rid of incidental dependency-dependencies that one currently needs to spend time sorting out. Makes sense! A bunch of questions...

Comment thread resources/idlharness.js Outdated
Object.values(this["implements"]).forEach(v => all_deps.add(v));
this.partials.map(p => p.name).forEach(v => all_deps.add(v));

console.log('all deps', all_deps);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Remember to remove logging before merging :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

Comment thread resources/idlharness.js Outdated

const all_deps = new Set();
Object.values(this["inheritance"]).forEach(v => all_deps.add(v));
Object.values(this["implements"]).forEach(v => all_deps.add(v));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should "includes" also be processed here? That's for mixins, added in #8727

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I treat it as a dep type below, so yeah, I think it should.

Comment thread resources/idlharness.js
const all_deps = new Set();
Object.values(this["inheritance"]).forEach(v => all_deps.add(v));
Object.values(this["implements"]).forEach(v => all_deps.add(v));
this.partials.map(p => p.name).forEach(v => all_deps.add(v));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Use this["partials"] here, or this.inheritance + this.implements above?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

Comment thread resources/idlharness.js Outdated
if (options && options.except && options.only) {
throw new IdlHarnessError("The only and except options can't be used together.");
}
const skip = name => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is very similar to the function should_skip(name) in internal_add_idls. Can you copy that so that any differences stand out, or, if it seems worthwhile, use a shared definition?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added is_excluded_by_options

Comment thread resources/idlharness.js Outdated
}

// Mark as untested.
for (var i = 0; i < parsed_idls.length; i++) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Share with add_untested_idls?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added mark_as_untested

Comment thread resources/idlharness.js Outdated
}
}

if (follow_up && skipped.has(follow_up)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This seems broken. follow_up is an array, and even an empty array is truthy in JS (unlike in Python). Should have been a loop?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

Comment thread resources/idlharness.js
console.log(parsed);

new_options.only.push(name);
const follow_up = [];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you add a comment about what this bookkeeping is for? I think it's in case we have a dependency on B, which in turn depends on C, but we've already processed C. However, since add_dependency_idls can be called multiple times, once for each IDL file, it seems like this will still be broken for cross-spec dependencies. Most likely, some spec depends on something in HTML, that depends on something in DOM, but we process DOM before HTML. Does this still work then?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No; it still requires the caller to load the dep files in the right order, unfortunately.

I could change things to be more global, but I think that's too stateful and risky.

@foolip foolip May 15, 2018 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, something more global would not necessarily be an improvement, if we wanted order-agnosticism we should probably delay parsing until idl_array.test() or something. Not today.

The "Record of skipped items in case we later determine they are a dependency" comment is clear to me now. Could possibly say that it's not global, but that's a pretty far-fetched misunderstanding, so nah.

Comment thread resources/idlharness.js
if (parsed_idl.name in this["inheritance"]
&& parsed_idl["inheritance"] != this["inheritance"][parsed_idl.name]) {
throw new IdlHarnessError(
`Inheritance for ${parsed_idl.name} was already defined`);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A new idlharness.js test for this error?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

@wpt-pr-bot
wpt-pr-bot requested a review from tobie May 14, 2018 20:11

@lukebjerring lukebjerring left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

PTAL!

Comment thread resources/idlharness.js
const all_deps = new Set();
Object.values(this["inheritance"]).forEach(v => all_deps.add(v));
Object.values(this["implements"]).forEach(v => all_deps.add(v));
this.partials.map(p => p.name).forEach(v => all_deps.add(v));

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

Comment thread resources/idlharness.js Outdated
Object.values(this["implements"]).forEach(v => all_deps.add(v));
this.partials.map(p => p.name).forEach(v => all_deps.add(v));

console.log('all deps', all_deps);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

Comment thread resources/idlharness.js Outdated
if (options && options.except && options.only) {
throw new IdlHarnessError("The only and except options can't be used together.");
}
const skip = name => {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added is_excluded_by_options

Comment thread resources/idlharness.js
console.log(parsed);

new_options.only.push(name);
const follow_up = [];

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No; it still requires the caller to load the dep files in the right order, unfortunately.

I could change things to be more global, but I think that's too stateful and risky.

Comment thread resources/idlharness.js Outdated
}
}

if (follow_up && skipped.has(follow_up)) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

Comment thread resources/idlharness.js Outdated
}

// Mark as untested.
for (var i = 0; i < parsed_idls.length; i++) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added mark_as_untested

Comment thread resources/idlharness.js
if (parsed_idl.name in this["inheritance"]
&& parsed_idl["inheritance"] != this["inheritance"][parsed_idl.name]) {
throw new IdlHarnessError(
`Inheritance for ${parsed_idl.name} was already defined`);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

@foolip foolip left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM % small nits. Although most changes are contained to add_dependency_idls it's still not far fetched that there might be regressions. Before merging, can you run the updated tests and a handful of tests that haven't been changed to see if it's all good? (Or put it through Chromium's CQ.)

Comment thread resources/idlharness.js
var parsed_idls = WebIDL2.parse(raw_idls);
for (var i = 0; i < parsed_idls.length; i++)
{
this.mark_as_untested(parsed_idls);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is short and sweet now, nice!

Comment thread resources/idlharness.js Outdated
throw new IdlHarnessError("The only and except options can't be used together.");
}

const skip = name => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you name this should_skip like the other one?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

Comment thread resources/idlharness.js Outdated
IdlArray.prototype.is_excluded_by_options = function (name, options)
//@{
{
return !name ||

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you hoist the !name part of this to the one (right?) call site where it's possible for it to be falsy? I actually don't really get why it can be falsy, but it does seem like when there's nothing to skip the return value from this method can't matter, and the purpose of the check will be more clear closer to the origin of the value.

Comment thread resources/idlharness.js
|| parsed.type == "implements" && parsed.target
|| parsed.type == "includes" && parsed.target;
if (skip(name) || !all_deps.has(name)) {
if (!name || should_skip(name) || !all_deps.has(name)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Still can't quite tell why it's possible for name to be null. Is it parsed.target which can be null?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If the chunked is unnamed and doesn't implement/include. Can't recall the case that isn't any of these, but I definitely hit it in my testing.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is "chunked" a typo? This is fine in any case, but it probably will be hard to figure out if it's safe to change later. I guess checking if any tests are affected will always work though.

@lukebjerring

Copy link
Copy Markdown
Contributor Author

@wpt-pr-bot
wpt-pr-bot requested a review from beverloo May 17, 2018 17:46
@lukebjerring

Copy link
Copy Markdown
Contributor Author

@foolip - to fix the breakage of Animation idl test, there are 2 major changes:

  • Attributes of tested IDLs are included as dependencies
  • Encountering a dep which is already a member of the idlarray is ignored

The second change occurs when A : B and B : C and you want to test A and B, but not C. Adding deps for the same file means that B is re-encountered (and would clash / already exist). See the Animation test file for more context.

Note that the reason to add_dependency_idls from the same file is that only part of the web-animation IDL is (currently) tested, so to get a no-op result, needed to stay that way.

@foolip foolip left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM % possible comment.

Maybe it's just because I've read it over and over, but I think this is all nice and understandable now, which is rarely true in this file. Thanks!

Comment thread resources/idlharness.js Outdated
}

const should_skip = name => {
return this.is_excluded_by_options(name, options) || name in this.members;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should this same condition also apply to the other should_skip? Just a comment about what the name in this.members bit is for would calm the nervous reader.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No; we don't want to be lenient with tested IDL. Large comment added.

Comment thread resources/idlharness.js
// e.g. for 'idl' containing A:B, B:C, C:D
// array.add_idls(idl, {only: ['A','B']}).
// array.add_dependency_idls(idl);
// B would be encountered as tested, and encountered as a dep, so we ignore.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah, great comment, thank you!

@lukebjerring
lukebjerring merged commit b47939b into web-platform-tests:master May 17, 2018
@lukebjerring
lukebjerring deleted the idlharness-dependencies branch May 17, 2018 22:45
foolip pushed a commit that referenced this pull request Jun 11, 2018
Follow up for #9763 now that #10338 is resolved and we have #10381 too.
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.

4 participants