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

Analyzing spec algorithms #663

Open
tidoust opened this issue Aug 1, 2024 · 1 comment
Open

Analyzing spec algorithms #663

tidoust opened this issue Aug 1, 2024 · 1 comment

Comments

@tidoust
Copy link
Member

tidoust commented Aug 1, 2024

Context: algorithms extraction

Reffy now extracts algorithms from specs, see algorithms extracts in Webref. Extraction is far from perfect (a number of limitations are noted as TODO comments in the extraction logic) but the results are still good enough to start analyzing potential problems in algorithms, see study-algorithms.js.

Also see @dontcallmedom's initial algorithms explorer based on the extracts.

Analysis: parallel steps that should call "queue a task"

First thing I analyzed are steps that run in parallel because I always forget the need to queue a task within parallel steps before resolving/rejecting a Promise or firing an event. @jyasskin noted the same problem back in 2022 in whatwg/html#8569. What's new here is that we can now compute that information automatically, giving us more weapons to play whack-a-mole.

The results show that about 50% of the specs (56/113) that define algorithms with "in parallel" steps need fixing:

Specs with steps in parallel that miss a call to "queue a task" (56 specs)

To run the analysis and refresh the above results, retrieve Webref's latest crawl results data locally and run:

npx strudy inspect [pathto]/webref --what algorithms --structure type/spec --sort default/title > res.md

On top of these problems (Edit: both examples have been fixed):

We could start reporting these problems to spec authors on a semi-automated basis (after review) as we do for broken links. Now, as noted by @jyasskin in whatwg/html#8569, "queue a task" means selecting a task source, which is also something that people get confused about (looking into it, I realize that I raised w3ctag/design-principles#38 on this topic back in 2016), and often choose to ignore.

Given the number of specs that get it wrong, two questions that I'm wondering about:

  1. Would it be better to consider less error prone ways to write such steps first?
  2. Do these problems materialize in interoperability bugs? Should we rather keep that in the back burner if it does not have practical implications?

Further analyses

Additional analyses that could be done:

  • Look into task sources as well. Whether a task source is defined is a bit harder to evaluate automatically because various specs have a blanket "use the foo task source for all tasks in this specification" statement; but the name of the task source is usually wrapped in a <dfn>, which should be easy to detect.
  • Report terms in steps that should link to their formal definition (e.g., "in parallel", "queue a task") and that don't.
  • Look into phrasing conventions when defining an algorithm and calling an algorithm, to progressively converge on a similar pseudo-language for algorithms. See how to define an algorithm in Infra for the definition part.
  • Start tracking algorithm variables, inputs and outputs. That probably requires settling down on stricter conventions first.
  • Analyze the list of step operations. In the extraction logic, the list is used to assess that a list item is indeed part of an algorithm. It reveals the many verbs that specs use to tell implementers what needs to be done. Some have formal definitions. The meaning of others is more fuzzy. Ideally, the meaning of all operations would be normatively defined somewhere.

Any other interesting or important analyses that could be worth looking into?

How to write/flag algorithms

More broadly speaking, algorithms are currently written with semi-formal structures. There are opportunities to converge on a more formal structure if that seems useful. Examples:

  • Infra describes how to define an algorithm. Specs use other variants here and there, such as "When the foo() method is invoked, run the following steps...", or algorithms sections where the sub-heading's title is the name of the algorithm.
  • Specs and spec authoring tools follow different conventions with regards to flagging these algorithms, e.g., with a class="algorithm" attribute. This makes it harder to extract the relevant prose, algorithm name, and actual steps.
  • Algorithm steps may be more or less atomic. Sometimes, a single step performs multiple operations (e.g., if/then/else all in one sentence). Related discussions about "inlining" steps in HTML in "in parallel" in algorithm headers can be confusing whatwg/html#10049

On top of us raising issues afterwards, spec authoring tools could perhaps better guide spec authors at the authoring step. Additional classes could also help make algorithms visually more readable, as attempted with flowchart symbols in the algorithms explorer.

In any case, convergence would make it easier to extract the algorithms and run further analyses.

tidoust added a commit that referenced this issue Aug 26, 2024
Specs are sorted per URL in browser-specs. That order is not fantastic
when preparing a human-readable report such as the one in:
#663

The --sort option lets makes it possible to specify the order to follow
at each level of the structured report: one of "default", "name" or
"title". We may want to add additional possibilities over time.
tidoust added a commit that referenced this issue Aug 26, 2024
Specs are sorted per URL in browser-specs. That order is not fantastic
when preparing a human-readable report such as the one in:
#663

The --sort option lets makes it possible to specify the order to follow
at each level of the structured report: one of "default", "name" or
"title". We may want to add additional possibilities over time.
@tidoust
Copy link
Member Author

tidoust commented Sep 6, 2024

Status update:

  • Strudy was re-written to ease semi-automatic reporting of various types of anomalies.
  • This made it possible to file "missing "ueue a task" issues against specifications, which we've now started to do. That may take a bit of time but anomalies reported above should end up being reported.
  • I sent a message to spec-prod to initiate a larger discussion about algorithms

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

No branches or pull requests

1 participant