tc39 / proposal-atomics-wait-async

"asynchronous atomic wait" for ECMAScript
https://tc39.github.io/proposal-atomics-wait-async/
Other
89 stars 18 forks source link

Stage 3 reviews #16

Open littledan opened 5 years ago

littledan commented 5 years ago

Reviewers:

Editors:

littledan commented 5 years ago

I've reviewed this text, and the big issues I see are in #13 and #15, which I'd like to see resolved before Stage 3. I'll do my best to review the fixes, but I'll be on leave starting July 1st through August 30th, and I'll defer to others on reviewing the rest of the fixes.

littledan commented 4 years ago

The issues I reported seem to be fixed, or have fixes along the way, so LGTM for Stage 3 from me.

ljharb commented 4 years ago
syg commented 4 years ago

@ljharb Thanks for the catches! All but the last bullet point should be fixed after #18 was merged, PTAL.

As for the refactoring I'll be happy to for the final merge into the main spec. I don't much feel like typing out a bunch of <ins> and <del> tags will help the stage 3 review. :)

ljharb commented 4 years ago

Thanks! Updated review:

syg commented 4 years ago
syg commented 4 years ago

I've done the record refactoring and pushed it to master: https://tc39.es/proposal-atomics-wait-async/#sec-getwaiterlist

I have the AO refactoring in a separate branch and will open a PR for you to take a look. I'm personally not a fan of the refactored AO because of the conditionals inside.

Edit: Note that the current master is layered on top of the yet unmerged https://github.com/tc39/ecma262/pull/1692, which I dare hope is uncontroversial and will be merged next week.

syg commented 4 years ago

@kmiller68 Review ping, would like to advance to stage 3 next meeting.

kmiller68 commented 4 years ago

@kmiller68 Review ping, would like to advance to stage 3 next meeting.

Whoops sorry, I wish GitHub had a better way to notify me when someone @s me. Anywho, this is my first review so bear with me.

https://tc39.es/proposal-atomics-wait-async/#sec-addwaiter seems wrong when run from waitAsync. Currently it says:

1. If waiterRecord.[[PromiseCapability]] is undefined, then
    a. Assert: There is no Waiter Record in WL.[[Waiters]] whose [[AgentSignifier]] field is waiterRecord.[[AgentSignifier]].
    b. For each element wr in WL.[[Waiters]], do
        i. If wr.[[AgentSignifier]] is waiterRecord.[[AgentSignifier]], then
            1. Insert waiterRecord to immediately precede wr in WL.[[Waiters]].
            2. Set inserted to true.

Is the intention that you can't have more than one async waiter for an address? I'm guessing there should be an else between a. and b.?

Additionally, why does waiterRecord go before wr? Isn't that a stack system? That's definitely wrong since you could in effect see any ordering of resolution for a given thread. Also, and probably more importantly, why do we insert right after the last record for the same agent? IMO, the waiter list should just be a global FIFO queue for a given "address".

It also looks like https://tc39.es/proposal-atomics-wait-async/#sec-addwaiter lost it's indenting for the then block. Idk, if that's important.

syg commented 4 years ago

Is the intention that you can't have more than one async waiter for an address? I'm guessing there should be an else between a. and b.?

The opposite, that you can't have more than one sync waiter for an address. That whole if block is "if the promise capability is undefined", i.e. from Atomics.wait. The async case is the "if inserted is false" block below this one.

Additionally, why does waiterRecord go before wr?

That's the "sync waits skip the line" semantics we've discussed. Rationale being if a thread is blocked, resolving its asyncWait promises are pretty useless without first unblocking the thread.

Also, and probably more importantly, why do we insert right after the last record for the same agent?

Where is this done? A synchronous waiterRecord for an agent always ends up before any other record for that agent in the waiter queue, while an asynchronous waiterRecord goes after every other record for that agent.

IMO, the waiter list should just be a global FIFO queue for a given "address".

Yeah, for async waiters, it is a per-address FIFO queue. But it also keeps track of the synchronous waits with the line-skipping logic, which is why the logic gets more complicated.

kmiller68 commented 4 years ago

Is the intention that you can't have more than one async waiter for an address? I'm guessing there should be an else between a. and b.?

The opposite, that you can't have more than one sync waiter for an address. That whole if block is "if the promise capability is undefined", i.e. from Atomics.wait. The async case is the "if inserted is false" block below this one.

AHH, I think the assert is wrong then (and threw me off >.>). I think the assert should be: Assert: There is no Waiter Record in WL.[[Waiters]] whose **[[PromiseCapability]] is not undefined and** [[AgentSignifier]] field is waiterRecord.[[AgentSignifier]].

The rest makes sense now. Ignore my other comments, except the indentation one.

syg commented 4 years ago

Oh doh, that assert most def is wrong, thanks for the catch.

Btw which then block lost its indentation? All the then blocks (step 4.a-b, 4.b.i.1-2, 5.a, 6.a-b) look indented to me.

kmiller68 commented 4 years ago

Btw which then block lost its indentation? All the then blocks (step 4.a-b, 4.b.i.1-2, 5.a, 6.a-b) look indented to me.

Ugh, sorry I pasted the wrong link before. I meant to link to: https://tc39.es/proposal-atomics-wait-async/#sec-entercriticalsection

syg commented 4 years ago

Ah, will fix.

syg commented 4 years ago

The two issues @kmiller68 raised have been addressed in defee82967f56f5c92eb05d6b475190258eb80ca and 87210b5c8ac686727063e3582417899df000f094

kmiller68 commented 4 years ago

Cool, LGTM now.

syg commented 4 years ago

Thank you for the reviews.

ljharb commented 4 years ago

Other than these items, consider me signed off.

syg commented 4 years ago

@ljharb Thanks for the review

ljharb commented 4 years ago

Sounds good.

syg commented 4 years ago

I've decided to change the semantics of Atomics.wait to not cut the line and to keep a single per-location FIFO queue for both sync and async waiters. In light of that, I'd like the reviewers to review #20 before the next meeting if possible. It's a small, but major change.

rwaldron commented 4 years ago

During the course of writing tests for Test262, I've completed a first pass review and filed issues from my findings (all of which have been fixed—thanks @syg!). I will continue to file issues and propose fixes as I encounter them.

@littledan I feel comfortable giving a ✔️ for my Stage 3 review.