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

Editorial: rigorize tasks and task queuing #4465

Merged
merged 4 commits into from
Apr 30, 2019
Merged

Conversation

domenic
Copy link
Member

@domenic domenic commented Mar 29, 2019

This introduces tasks as a proper struct, with well-defined fields, and
makes "queue a task" and "queue a microtask" into more well-defined
algorithms for setting up and queuing those tasks. It centralizes and
calls out the still-somewhat-vague parts in the "implied event loop" and
"implied document" definitions.

Other minor cleanups and clarifications:

  • Fixes "performing a microtask checkpoint" to be a boolean; previously
    it was referred to as a flag but set to true or false.
  • Fixes Script event-loop: ignoring tasks for documents that are not fully active #4242 by making it clearer how tasks are chosen by the event
    loop.
  • Adds more guidance text around how task sources and task queues
    interact.
  • Introduces a new subsection "Queuing tasks" to contain the
    task-queuing definitions, which were previously spread out through
    "Definitions" (for non-microtask tasks) and "Processing model" (for
    microtasks).
  • Centralizes all properties of the event loop into "Definitions". They
    were previously spread out throughout "Definitions" and "Processing
    model".

/cc @littledan, although this is probably only tangentially related to stuff you've been thinking about.


Interesting things to note about the task struct is how rarely some of its fields are used:

  • type is not really used. I guess I will try to remove it in a second commit which we can squash.
  • source is only used because spin the event loop can suspend a task and then we need to put the continuation back onto the same task source

/index.html ( diff )
/webappapis.html ( diff )

This introduces tasks as a proper struct, with well-defined fields, and
makes "queue a task" and "queue a microtask" into more well-defined
algorithms for setting up and queuing those tasks. It centralizes and
calls out the still-somewhat-vague parts in the "implied event loop" and
"implied document" definitions.

Other minor cleanups and clarifications:

* Fixes "performing a microtask checkpoint" to be a boolean; previously
  it was referred to as a flag but set to true or false.
* Fixes #4242 by making it clearer how tasks are chosen by the event
  loop.
* Adds more guidance text around how task sources and task queues
  interact.
* Introduces a new subsection "Queuing tasks" to contain the
  task-queuing definitions, which were previously spread out through
  "Definitions" (for non-microtask tasks) and "Processing model" (for
  microtasks).
* Centralizes all properties of the event loop into "Definitions". They
  were previously spread out throughout "Definitions" and "Processing
  model".
@domenic domenic requested a review from annevk March 29, 2019 18:54
@domenic domenic added clarification Standard could be clearer topic: event loop labels Mar 29, 2019
source Show resolved Hide resolved
<dd>A <code>Document</code> associated with the task, or null for tasks that are not in a
<span>window event loop</span>.</dd>

<dt>A <dfn data-export="">script evaluation environment settings object set</dfn></dt>
Copy link
Member

Choose a reason for hiding this comment

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

Why is only this field exported?

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 one is referenced from the long tasks spec. None of the others were exported at this time, and probably should not be.


<p>To <dfn data-export="">queue a task</dfn> on a <span>task source</span> <var>source</var>,
which performs a series of steps <var>steps</var>, optionally given an event loop <var>event
loop</var>:</p>
Copy link
Member

Choose a reason for hiding this comment

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

This requires rephrasing almost all callers, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

To introduce a "on the X task source"? Yes, that's the intent, is to require being explicit there. Or did you mean something else?

Copy link
Member

Choose a reason for hiding this comment

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

Well, that this PR doesn't change any callers.

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 thought we could do that as a follow-up, to avoid this growing into a mega-patch. Do you think it's necessary to do that in the same patch?

Copy link
Member

Choose a reason for hiding this comment

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

Not necessarily, if it'll happen.

Copy link
Member Author

Choose a reason for hiding this comment

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

Filed #4506 to track. Do you think it's worth linking to in the meantime, from the spec?

below.</p></li>
on one of the <span>event loop</span>'s <span data-x="task queue">task queues</span>. In the case
of a <span>window event loop</span>, the task selected must have a <span
data-x="concept-task-document">document</span> that is <span>fully active</span>. The user agent
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this has quite the same meaning as the old text. This is a requirement on the selected task, whereas before it was a requirement on how to select.

Copy link
Member Author

Choose a reason for hiding this comment

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

What would the new text allow/disallow that the old text did not?

Copy link
Member

Choose a reason for hiding this comment

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

The new text is unclear to me. I select the oldest task. It violates the must, now what?

Copy link
Member Author

Choose a reason for hiding this comment

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

You're not allowed to do things that violate the must, so you don't do that.

Can you suggest alternate phrasing that fixes the concerns in #4242? This was my best attempt.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can make it an algorithm instead?

Let oldest task be the oldest task.
While true:

  1. If oldest task's document is null or is fully active, then break.
  2. Set oldest task to the task following oldest task.

- Task queues are sets, not lists, and not queues. Explains why.
- Microtask queue can be a queue.
- Explain that not just source, but also document and script evaluation environment settings object set, are irrelevant in most cases for microtask.
- Fix oldestTask selection algorithm to be more precise, by introducing a "runnable" task concept.
- Use more Infra
Copy link
Member

@annevk annevk left a comment

Choose a reason for hiding this comment

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

This looks pretty great to me. Perhaps we should find one additional reviewer though given the complexity of the algorithm. Alternatively I could give it a fresh look next week to see if it still makes sense.

<dl>
<p class="note"><span data-x="task queue">Task queues</span> are <span data-x="set">sets</span>,
not <span data-x="queue">queues</span>, because <a href="#step1">step one of the event loop
processing model</a> grabs the first <span data-x="concept-task-runnable"><em>runnable</em></span>
Copy link
Member

Choose a reason for hiding this comment

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

s/grabs/removes/?

event loop</span>. This is the only case in which the <span
data-x="concept-task-source">source</span>, <span data-x="concept-task-document">document</span>,
and <span>script evaluation environment settings object set</span> of the microtask are consulted;
they are ignored by the <span>perform a microtask checkpoint</span> algorithm.</p>
Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting! This is news to me. I thought we processed the microtask queue after looking for an item in the task queues (whether a task is found or not).

<li><p>If <var>event loop</var> is not a <span>window event loop</span>, then return
null.</p></li>

<li><p>If the task is being queued in the context of an element, then return the element's
Copy link
Contributor

Choose a reason for hiding this comment

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

What does "in the context of an element" mean? Does it mean it looks inside the task to see what the algorithm acts upon?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's pretty fuzzy, to be honest. This is just porting the preexisting vague language.

queue</span>. If there is no task to select, then jump to the <i>microtasks</i> step
below.</p></li>
<li id="step1"><p>Let <var>taskQueue</var> be one of the <span>event loop</span>'s <span
data-x="task queue">task queues</span>, chosen in a user-agent-defined manner, with the
Copy link
Contributor

Choose a reason for hiding this comment

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

Could it end up picking the microtask task queue at this point?

Copy link
Member Author

Choose a reason for hiding this comment

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

The "microtask queue" is not a "task queue"; all "task queues" are implementation-defined. I will add a note making that explicit.

@domenic
Copy link
Member Author

domenic commented Apr 26, 2019

If @annevk or @jakearchibald wants to take another look at my latest commit, I'd love to commit this :).

Copy link
Member

@annevk annevk left a comment

Choose a reason for hiding this comment

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

I'm still happy with this.

@domenic domenic merged commit f4e2907 into master Apr 30, 2019
@domenic domenic deleted the domenic/clarify-event-loop branch April 30, 2019 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clarification Standard could be clearer topic: event loop
Development

Successfully merging this pull request may close these issues.

Script event-loop: ignoring tasks for documents that are not fully active
3 participants