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

Web IDL: Check overloaded operations and redefined members #347

Merged
merged 3 commits into from
Apr 14, 2023

Conversation

tidoust
Copy link
Member

@tidoust tidoust commented Apr 13, 2023

This completes the Web IDL study tool with checks to report on invalid overloaded operations and duplicated members within interface definitions but also across partials, mixins and partial mixins. Two new types of anomalies get reported: overloaded and redefinedMember.

As opposed to the test logic in Webref, no actual merge is being performed. Definitions are rather compared one by one, which makes it possible to report more fine-grained anomaly messages and in particular to target the spec that likely needs fixing.

Typically, when a partial dfn introduces a conflict with a base dfn, it seems logic to blame the partial dfn. Similarly, when a dfn introduces a conflict with one of its mixins, it seems logic to blame the dfn, since the dfn includes the mixin and not the other way round.

Only cases when multiple specs need to be blamed is when two specs create overloads in partial dfns (no a priori reason to consider that a partial has priority over another partial).

Note that the code will create multiple similar anomalies when the same method is overloaded in more than 2 partial dfns and in more than 2 specs. That is, theoretically, report could contain only one anomaly for the overloaded operation, linked to all specs that define the overload, but in practice report will contain one anomaly per pair of specs. That's not wrong per se, just not optimized. Such situations should not happen much in practice, if at all, unless the IDL starts being very clunky.

This update also rewrites tests to check on the number of anomalies first and report a dump of the report or anomaly when assertion fails. This is to ease debugging when a test fails.

Additional notes:

  • I haven't tried the code on actual crawl results yet, so I wouldn't be surprised if I missed a few cases here and there. Hopefully, the logic is sound :) Code seems to yield consistent results on Webref non curated data, haven't tried yet with curated data. Code tested on curated Webref data. It reports 3 incompatiblePartialIdlExposure anomalies for MSE v2 (known spec issues, base interfaces need to be exposed in DedicatedWorker), which actually should have been detected by Webref's tests... It also reports a couple of unexpectedEventHandler anomalies (already reported as errors against the specs), and a number of enum anomalies (case or single value) that we will probably want to ignore in Webref.
  • Checks on exposure to make sure that there is no overlap for members that have the same name but different exposure are still TBD. Same thing as in Webref tests!

This completes the Web IDL study tool with checks to report on invalid
overloaded operations and duplicated members within interface definitions but
also across partials, mixins and partial mixins. Two new types of anomalies get
reported: `overloaded` and `redefinedMember`.

As opposed to the test logic in Webref, no actual merge is being performed.
Definitions are rather compared one by one, which makes it possible to report
more fine-grained anomaly messages and in particular target the spec that
likely needs fixing.

Typically, when a partial dfn introduces a conflict with a base dfn, it seems
logic to blame the partial dfn. Similarly, when a dfn introduces a conflict with
one of its mixins, it seems logic to blame the dfn, since the dfn includes the
mixin and not the other way round.

Only cases when multiple specs need to be blamed is when two specs create
overloads in partial dfns (no a priori reason to consider that a partial has
priority over another partial).

Note that the code will create multiple similar anomalies when the same method
is overloaded in more than 2 partial dfns and in more than 2 specs. That is,
theoretically, report could contain only one anomaly for the overloaded
operation, linked to all specs that define the overload, but in practice report
will contain one anomaly per pair of specs. That's not wrong per se, just not
optimized. Such situations should not happen much in practice, if at all, unless
the IDL starts being very clunky.

This update also rewrites tests to check on the number of anomalies first and
report a dump of the report or anomaly when assertion fails. This is to ease
debugging when a test fails.
Copy link
Member

@dontcallmedom dontcallmedom left a comment

Choose a reason for hiding this comment

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

Impressive! the test suite is in particular chef-kiss-worthy! a few bugs / clarifications worth fixing

src/lib/study-webidl.js Outdated Show resolved Hide resolved
@@ -285,6 +344,87 @@ async function studyWebIdl(edResults, curatedResults) {
}
}

function checkMembers(target, source) {
const selfCheck = !source;
source = source ?? target;
Copy link
Member

Choose a reason for hiding this comment

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

maybe it would be clearer to have:

source = source ?? target;
const selfCheck = source === target;

Copy link
Member

Choose a reason for hiding this comment

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

or even

function checkMembers(target, source = target) {
  const selfCheck = source === target;

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 used the first approach. Second approach would not catch calls such as checkMembers(obj, null) as documented on MDN, which I always find confusing.

src/lib/study-webidl.js Show resolved Hide resolved
src/lib/study-webidl.js Show resolved Hide resolved
src/lib/study-webidl.js Show resolved Hide resolved
test/study-webidl.js Outdated Show resolved Hide resolved
test/study-webidl.js Outdated Show resolved Hide resolved
test/study-webidl.js Outdated Show resolved Hide resolved
test/study-webidl.js Outdated Show resolved Hide resolved
test/study-webidl.js Outdated Show resolved Hide resolved
See #347 (comment) for context

Update also improves readability of `selfCheck` and fixes check on mixins'
length.
New more specific assert methods defined in particular. One to check the number
of anomalies received, and one to check that an anomaly object "matches" the
expected anomaly object, in the sense that it contains the expected properties
with "matching" values for these properties.

The lodash library is no longer needed as a result.
Copy link
Member

@dontcallmedom dontcallmedom left a comment

Choose a reason for hiding this comment

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

brilliant, thanks :)

@dontcallmedom dontcallmedom merged commit b337292 into main Apr 14, 2023
@dontcallmedom dontcallmedom deleted the study-webidl-overloaded branch April 14, 2023 14:47
dontcallmedom pushed a commit that referenced this pull request Apr 14, 2023
See #347 (comment) for context

Update also improves readability of `selfCheck` and fixes check on mixins'
length.
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.

2 participants