-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Markup: Wrap algorithms in <div> tags #11392
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
Conversation
|
Out of curiosity, why use a different attribute marker to indicate an algorithm than what Bikeshed uses? There's certainly no, like, interop between the documents, but using identical patterns when possible reduces mental load for spec authors that touch multiple specs. It looks like a major reason might be that about half the "algorithms" don't scope their variables, per your numbers. Can you expand on that? |
Using the same marker might have suggested it has the same semantics, which I don't think it does (though there's a lot of overlap). One difference is that the (optional) value of Bikeshed's But certainly, if the HTML editors would like the spec to be more like Bikeshed in this regard, that can be done.
It's not that they don't scope their variables, it's that they don't have variables to scope. E.g.
Although "a parallel queue" and "the parallel queue" are basically the declaration and use of a parameter, it doesn't use any Other examples are where an algorithm's only use of (what you might think of as) a parameter is to say And then there are cases like in 2.6.1 Reflecting content attributes in IDL attributes, where "For a reflected target that is an element element, these are defined as follows:" introduces a One caveat is that I mostly ignore |
|
My reaction is the same as @tabatkins. This is more than I anticipated in #10483 (comment). And I worry that trying to guarantee this level of fine-grained metadata going forward will be a burden on contributors. Can we just use Additional note: dff98e6 does not match our style guide. https://github.com/whatwg/html/blob/main/CONTRIBUTING.md#element-hierarchy |
It's certainly more than you described, and I knew that when I created the PR, but like I said, it's more of a discussion-starter than a solid proposal.
Yup.
Certainly. I'll explain more about why this draft has (1) Similarly, the Web IDL spec gives particular wording for defining behavior, but looking for just that wording will miss lots. So one thing I did was read the spec's Web IDL fragments, to figure out what behavior-algorithms would need to appear elsewhere in the spec. So if the algorithms I had tagged so far didn't cover that, I would need to look further (i.e., look for other phrasings). The granular (2) (3)
To be clear, I didn't introduce So sure, we can say that every algorithm is implictly a variable scope, and so drop
Sure, but like I said, that commit's only there to make the main commit cleaner. (That is, in the main commit, every new Or are you saying that the later commit doesn't fix it? Currently, the PR says According to the style sheet, I guess this should be because both the Or maybe you'd prefer but then I have to ask if you'd like a similar treatment for other cases where the new Of course, rather than introducing a |
|
Thanks for your detailed reply! I think I'm aligned on most points. To summarize:
Regarding the eventual end state, do you think Anyway, I'll try to do a more detailed review pass now! |
|
So, the diff is huge, and not reviewable on GitHub. But reviewing it locally, the following things stood out to me from, like, the first 10%, plus some skipping around.
|
You looked at cases of (Looking at the 3rd
I'm pretty sure that just |
This makes sense, and is something I wouldn't mind introducing to Bikeshed as well. (And that name, But in Bikeshed, at least, it would be in addition to the var scoping that happens automatically for algorithms. For ease of comparison, I think it would be a good idea to assume that algorithms automatically scope their variables. (We can worry about to what extent we need to care about marking up a shared variable "inheriting into" nested scopes later, if at all. This is mostly for human convenience, and lightly for linting and styling, so it doesn't necessarily need to be too precise.) |
|
(Responding to just a couple points for now...)
Indeed, the variety of syntax is discouraging. I imagine I'll suggest some consistification to make analysis easier, but it probably won't make much of a dent in the non-uniformity.
Yeah, that's what I thought too. More generally, they are rich in statically checkable phrases, so it would be a shame not to check them.
It may be difficult to draw the line between algorithm-y and non-algorithm-y definitions.
I think the specific reason was just that I didn't look for dfn-paragraphs with that form. E.g., I probably would have included CORS-same-origin if it had been phrased as: "A response is CORS-same-origin if ..." or "To determine whether a response is CORS-same-origin, ..." Background: I didn't want to step through the whole HTML spec, asking for each paragraph in turn whether it should be marked as an algorithm. So instead [among other things] I 'scraped' paragraphs from the spec and tried to identify patterns of phrasing that looked like algorithms, and then (check and) mark-up the paragraphs using those patterns. Which has the failure mode of leaving things out. Anyway, I'll take another look.
The "has 53 weeks" paragraph got my attention because of the
Yes, I'm currently counting 84, ignoring examples, notes, and domintros. I think I only bothered creating a
Right there with you, and I'd happily work on it, like I did for EcmaScript. That could conceivably be an alternative to this PR, since if you have a distinct enough syntax for algorithm headers, you might not need |
|
(responding to the rest of Domenic's comment...)
Okay, cool.
I did have it marked as an algorithm for a while, but it was just too weird.
There's definitely a tooling-related reason to have struct info handy. E.g., if you want to validate (type-check) However, I'm not sure that
Standardizing either the markup or the introductory wording would be good.
It occurs to me that
There might be other cases where
I understand what you mean, but I don't think I have much to add to your points. |
|
I have renamed the previous commits of this PR (modified after rebasing) as "round1". I'm now adding 6 commits of "round2"... Commit 1 of round2 corrects some round1 markup. In #11392 (comment), @domenic said:
At the time, there were lots, but commits 2+3+4 of round2 clean that up: 2: In 13 cases, extend the scope of a The result of these changes is that every
(Or, eventually, "is within a So, in future, the build process can complain if it finds a
[Rather than "internal response", which is defined in Fetch, I think you mean "unsafe response".] I went through the spec with a medium-tooth comb, and found lots more algorithms, including the three you listed. Commit 5 of round2 inserts some linebreaks to make the next commit cleaner, and commit 6 adds 470 more Many of these are questionable. I'm not sure where to draw the line. |
|
Alright, so, how do we move toward landing this? I imagine floating this giant patch is not that fun. Here is a proposal, but feel free to give your thoughts:
|
…ing.css See whatwg/html#11392 (comment), 6th bullet.
|
Dealing with some easier things first...
I don't see where in the code to do this. Does it need a whole new Processor? If so, yeah, you'll probably need to do it.
Done: whatwg/whatwg.org#470
I've pushed a commit that adds that. It also adds a copy of the CSS file, just until the above PR is merged+published. For now, it keys off the attributes used in the current PR ("algo" and "var-scope"), though those will change. Basically, I just wanted to be able to see var-highlighting in the output of my local html-build. Not sure what will happen in the CI build. [Later: It doesn't work in the CI-built pages.] More to say tomorrow (I hope). |
|
I've almost got the preprocessor working; will try to post it soon. Some things to note:
|
|
Ah, also:
|
This supports the work in whatwg/html#11392 with a new processor found in variables.rs, documented there. This required updating the parser to store line numbers for each element, which changed a lot of test call sites.
This supports the work in whatwg/html#11392 with a new processor found in variables.rs, documented there. This required updating the parser to store line numbers for each element, which changed a lot of test call sites.
This supports the work in whatwg/html#11392 with a new processor found in variables.rs, documented there. This required updating the parser to store line numbers for each element, which changed a lot of test call sites.
When I looked at the bikeshed doc, I got the impression that they had different semantics: I intended
It would currently raise about 150 warnings. Some are false positives (e.g., unused parameters), and some appear to be true positives. Non-algorithmic var-scopes should maybe be exempt from the check.
Yeah, I think we agreed on that a while ago. Anyway, I've been assuming for a while that (eventually) |
Although I agree theoretically this could be a distinction, it turns out Bikeshed has a global scope, so there isn't really one:
That's not bad! Some good follow-up work then. |
|
More commits...
And then 2 commits re nested variable-scopes:
After these, the only cases of scope-nesting is where a |
For one, the For the others, they aren't defining an algorithm, just declaring it, to be defined (possibly multiple times) elsewhere. This is certainly algorithm-adjacent, and might be deserving of some markup eventually, but I'm guessing not yet. So I changed them to |
|
Okay, I think that's everything. |
* Various editorial updates to CONTRIBUTING * Fix var-click-highlighting to use the new attribute names * Use defer on var-click-highlighting script
domenic
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing work. I pushed a few minor tweaks, mostly just to the CONTRIBUTING guidelines. Please holler if you think any of them were incorrect.
I've tested this with whatwg/html-build#306 and I get variable highlighting!!
I'll work on the gymnastics for landing this ASAP, maybe today.
This is easier to maintain, as per work on whatwg/html#11392 we'll be adding a new JS file.
This is easier to maintain, as per work on whatwg/html#11392 we'll be adding a new JS file.
This supports the work in whatwg/html#11392 with a new processor found in variables.rs, documented there. This also updates the parser to store the line numbers for each element, for use in error messages.
This supports the work in whatwg/html#11392 with a new processor found in variables.rs, documented there. This also updates the parser to store the line numbers for each element, for use in error messages. For now this contains commented-out code to error on `<var>`s outside of `algorithm` and `var-scope` scopes, since CI will prevent us from merging a html-build change that cannot build the current main branch of whatwg/html. After the HTML PR is merged, we can uncomment that code.
This supports the work in whatwg/html#11392 with a new processor found in variables.rs, documented there. This also updates the parser to store the line numbers for each element, for use in error messages. For now this contains commented-out code to error on `<var>`s outside of `algorithm` and `var-scope` scopes, since CI will prevent us from merging a html-build change that cannot build the current main branch of whatwg/html. After the HTML PR is merged, we can uncomment that code.
A follow-up to adb2e6f, now that whatwg/html#11392 is merged.
|
I'm so glad we could land this! Thanks for all your hard work here; this will definitely improve the user experience of the spec going forward. Your patience for these sorts of large-scale refactors always impresses me. |
A follow-up to adb2e6f, now that whatwg/html#11392 is merged.
A follow-up to adb2e6f, now that whatwg/html#11392 is merged.
They look okay to me. I was so relieved to be done that I forgot some stuff, like taking care of the "INTERIM" comment in the JS, and doing one last rebase-to-main.
And thanks to you for your ongoing interest.
Patience is my superpower, I guess. |
(I'm creating this in draft mode, because at this stage it's more of a discussion-starter than a solid proposal.)
In issue #10483, @domenic raises the possibility of wrapping the HTML spec's algorithms in
<div algorithm>(as in Bikeshed specs). This PR does something approximating that.The first commit is a minor markup change that was originally in PR #11379, but fell out when I withdrew the
<hN>-related commits.The second commit just adds some linebreaks, so that the main commit has a cleaner diff.
In the main commit, I add 2269
<div>...</div>pairs.Each
<div>start tag has one or both attributes:var-scopealgo="..."(11 have only
var-scope, 1081 have onlyalgo, 1177 have both.)var-scopemeans: thisdivis a scope for<var>elements. (The main commit also inserts thevar-scopeattribute into 4<p>tags and 1<dd>tag, rather than introduce a<div>to hold thevar-scope.)algomeans: thisdivcontains some kind of algorithm, where the value of the attribute suggests the kind. (Occasionally, the value will show 2 kinds.)Behavior for attributes and operations declared in Web IDL fragments:
The classic: an algorithm is defined with a unique name + ID:
A named state of affairs exists if a given condition holds:
Integration with JavaScript:
Some other spec declares the algorithm, this spec gives steps for it:
(You could say that "js:host-defined-op" belongs here too.)
There's one 'abstract' declaration of the algorithm, but different kinds of object can have different definitions for the algorithm:
(You could say that "js:internal-method" belongs here too.)
When something occurs in the data model, the UA must perform some steps:
Parsing-related algorithms:
See below:
Algorithms that appear in examples, which might or might not be 'serious':
Abstract declarations of algorithms:
Things that are not actually algorithms, but I felt like identifying:
I don't know how to categorize it:
"main+subs" isn't a particular kind of algorithm, but rather a collection of algorithms, where there's one main algorithm that invokes others, but those others use variables defined in the main algorithm without taking them as parameters. (These need to be treated specially when it comes to checking for
<var>s being defined.) One way to think of these is as as macros that get inlined at the invocation-points. However, I prefer to think of them as algorithms that are conceptually nested at some point within the main algorithm, and so can 'see' the variables defined at that point. (Presumably they appear after the main algorithm to make the main algorithm easier to read.)/acknowledgements.html ( diff )
/browsers.html ( diff )
/browsing-the-web.html ( diff )
/canvas.html ( diff )
/common-dom-interfaces.html ( diff )
/common-microsyntaxes.html ( diff )
/comms.html ( diff )
/custom-elements.html ( diff )
/dnd.html ( diff )
/document-lifecycle.html ( diff )
/document-sequences.html ( diff )
/dom.html ( diff )
/dynamic-markup-insertion.html ( diff )
/edits.html ( diff )
/embedded-content-other.html ( diff )
/embedded-content.html ( diff )
/form-control-infrastructure.html ( diff )
/form-elements.html ( diff )
/forms.html ( diff )
/grouping-content.html ( diff )
/iana.html ( diff )
/iframe-embed-object.html ( diff )
/image-maps.html ( diff )
/imagebitmap-and-animations.html ( diff )
/images.html ( diff )
/index.html ( diff )
/indices.html ( diff )
/infrastructure.html ( diff )
/input.html ( diff )
/interaction.html ( diff )
/interactive-elements.html ( diff )
/introduction.html ( diff )
/links.html ( diff )
/media.html ( diff )
/microdata.html ( diff )
/named-characters.html ( diff )
/nav-history-apis.html ( diff )
/obsolete.html ( diff )
/parsing.html ( diff )
/popover.html ( diff )
/references.html ( diff )
/rendering.html ( diff )
/scripting.html ( diff )
/sections.html ( diff )
/semantics-other.html ( diff )
/semantics.html ( diff )
/server-sent-events.html ( diff )
/speculative-loading.html ( diff )
/structured-data.html ( diff )
/syntax.html ( diff )
/system-state.html ( diff )
/tables.html ( diff )
/text-level-semantics.html ( diff )
/timers-and-user-prompts.html ( diff )
/urls-and-fetching.html ( diff )
/web-messaging.html ( diff )
/webappapis.html ( diff )
/webstorage.html ( diff )
/workers.html ( diff )
/worklets.html ( diff )
/xhtml.html ( diff )